


<!DOCTYPE html>
<html id="htmlId">
<head>
  <title>Coverage Report > LinkedList</title>
  <style type="text/css">
    @import "../../.css/coverage.css";
    @import "../../.css/highlight-idea.css";
  </style>
  <script type="text/javascript" src="../../.js/highlight.pack.js"></script>
</head>

<body>
<div class="content">
<div class="breadCrumbs">
Current scope:     <a href="../../index.html">all classes</a>
    <span class="separator">|</span>
    <a href="../index.html">com.example.experiment5.mimic</a>
</div>

<h1>Coverage Summary for Class: LinkedList (com.example.experiment5.mimic)</h1>

<table class="coverageStats">

<tr>
  <th class="name">Class</th>
<th class="coverageStat 
">
  Method, %
</th>
<th class="coverageStat 
">
  Line, %
</th>
</tr>
<tr>
  <td class="name">LinkedList</td>
<td class="coverageStat">
  <span class="percent">
    8.6%
  </span>
  <span class="absValue">
    (5/58)
  </span>
</td>
<td class="coverageStat">
  <span class="percent">
    13.9%
  </span>
  <span class="absValue">
    (37/267)
  </span>
</td>
</tr>
  <tr>
    <td class="name">LinkedList$DescendingIterator</td>
<td class="coverageStat">
  <span class="percent">
    0%
  </span>
  <span class="absValue">
    (0/5)
  </span>
</td>
<td class="coverageStat">
  <span class="percent">
    0%
  </span>
  <span class="absValue">
    (0/5)
  </span>
</td>
  </tr>
  <tr>
    <td class="name">LinkedList$ListItr</td>
<td class="coverageStat">
  <span class="percent">
    0%
  </span>
  <span class="absValue">
    (0/12)
  </span>
</td>
<td class="coverageStat">
  <span class="percent">
    0%
  </span>
  <span class="absValue">
    (0/52)
  </span>
</td>
  </tr>
  <tr>
    <td class="name">LinkedList$LLSpliterator</td>
<td class="coverageStat">
  <span class="percent">
    0%
  </span>
  <span class="absValue">
    (0/7)
  </span>
</td>
<td class="coverageStat">
  <span class="percent">
    0%
  </span>
  <span class="absValue">
    (0/48)
  </span>
</td>
  </tr>
  <tr>
    <td class="name">LinkedList$Node</td>
<td class="coverageStat">
  <span class="percent">
    100%
  </span>
  <span class="absValue">
    (1/1)
  </span>
</td>
<td class="coverageStat">
  <span class="percent">
    100%
  </span>
  <span class="absValue">
    (5/5)
  </span>
</td>
  </tr>
<tr>
  <td class="name"><strong>Total</strong></td>
<td class="coverageStat">
  <span class="percent">
    7.2%
  </span>
  <span class="absValue">
    (6/83)
  </span>
</td>
<td class="coverageStat">
  <span class="percent">
    11.1%
  </span>
  <span class="absValue">
    (42/377)
  </span>
</td>
</tr>
</table>

<br/>
<br/>


<pre>
<div class="sourceCode" id="sourceCode"><i class="no-highlight">1</i>&nbsp;package com.example.experiment5.mimic;
<i class="no-highlight">2</i>&nbsp;
<i class="no-highlight">3</i>&nbsp;/*
<i class="no-highlight">4</i>&nbsp; * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
<i class="no-highlight">5</i>&nbsp; * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
<i class="no-highlight">6</i>&nbsp; *
<i class="no-highlight">7</i>&nbsp; * This code is free software; you can redistribute it and/or modify it
<i class="no-highlight">8</i>&nbsp; * under the terms of the GNU General Public License version 2 only, as
<i class="no-highlight">9</i>&nbsp; * published by the Free Software Foundation.  Oracle designates this
<i class="no-highlight">10</i>&nbsp; * particular file as subject to the &quot;Classpath&quot; exception as provided
<i class="no-highlight">11</i>&nbsp; * by Oracle in the LICENSE file that accompanied this code.
<i class="no-highlight">12</i>&nbsp; *
<i class="no-highlight">13</i>&nbsp; * This code is distributed in the hope that it will be useful, but WITHOUT
<i class="no-highlight">14</i>&nbsp; * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
<i class="no-highlight">15</i>&nbsp; * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
<i class="no-highlight">16</i>&nbsp; * version 2 for more details (a copy is included in the LICENSE file that
<i class="no-highlight">17</i>&nbsp; * accompanied this code).
<i class="no-highlight">18</i>&nbsp; *
<i class="no-highlight">19</i>&nbsp; * You should have received a copy of the GNU General Public License version
<i class="no-highlight">20</i>&nbsp; * 2 along with this work; if not, write to the Free Software Foundation,
<i class="no-highlight">21</i>&nbsp; * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
<i class="no-highlight">22</i>&nbsp; *
<i class="no-highlight">23</i>&nbsp; * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
<i class="no-highlight">24</i>&nbsp; * or visit www.oracle.com if you need additional information or have any
<i class="no-highlight">25</i>&nbsp; * questions.
<i class="no-highlight">26</i>&nbsp; */
<i class="no-highlight">27</i>&nbsp;
<i class="no-highlight">28</i>&nbsp;
<i class="no-highlight">29</i>&nbsp;import java.util.*;
<i class="no-highlight">30</i>&nbsp;import java.util.function.Consumer;
<i class="no-highlight">31</i>&nbsp;
<i class="no-highlight">32</i>&nbsp;/**
<i class="no-highlight">33</i>&nbsp; * Doubly-linked list implementation of the {@code List} and {@code Deque}
<i class="no-highlight">34</i>&nbsp; * interfaces.  Implements all optional list operations, and permits all
<i class="no-highlight">35</i>&nbsp; * elements (including {@code null}).
<i class="no-highlight">36</i>&nbsp; *
<i class="no-highlight">37</i>&nbsp; * &lt;p&gt;All of the operations perform as could be expected for a doubly-linked
<i class="no-highlight">38</i>&nbsp; * list.  Operations that index into the list will traverse the list from
<i class="no-highlight">39</i>&nbsp; * the beginning or the end, whichever is closer to the specified index.
<i class="no-highlight">40</i>&nbsp; *
<i class="no-highlight">41</i>&nbsp; * &lt;p&gt;&lt;strong&gt;Note that this implementation is not synchronized.&lt;/strong&gt;
<i class="no-highlight">42</i>&nbsp; * If multiple threads access a linked list concurrently, and at least
<i class="no-highlight">43</i>&nbsp; * one of the threads modifies the list structurally, it &lt;i&gt;must&lt;/i&gt; be
<i class="no-highlight">44</i>&nbsp; * synchronized externally.  (A structural modification is any operation
<i class="no-highlight">45</i>&nbsp; * that adds or deletes one or more elements; merely setting the value of
<i class="no-highlight">46</i>&nbsp; * an element is not a structural modification.)  This is typically
<i class="no-highlight">47</i>&nbsp; * accomplished by synchronizing on some object that naturally
<i class="no-highlight">48</i>&nbsp; * encapsulates the list.
<i class="no-highlight">49</i>&nbsp; *
<i class="no-highlight">50</i>&nbsp; * If no such object exists, the list should be &quot;wrapped&quot; using the
<i class="no-highlight">51</i>&nbsp; *
<i class="no-highlight">52</i>&nbsp; * method.  This is best done at creation time, to prevent accidental
<i class="no-highlight">53</i>&nbsp; * unsynchronized access to the list:&lt;pre&gt;
<i class="no-highlight">54</i>&nbsp; *   List list = Collections.synchronizedList(new LinkedList(...));&lt;/pre&gt;
<i class="no-highlight">55</i>&nbsp; *
<i class="no-highlight">56</i>&nbsp; * &lt;p&gt;The iterators returned by this class&#39;s {@code iterator} and
<i class="no-highlight">57</i>&nbsp; * {@code listIterator} methods are &lt;i&gt;fail-fast&lt;/i&gt;: if the list is
<i class="no-highlight">58</i>&nbsp; * structurally modified at any time after the iterator is created, in
<i class="no-highlight">59</i>&nbsp; * any way except through the Iterator&#39;s own {@code remove} or
<i class="no-highlight">60</i>&nbsp; * {@code add} methods, the iterator will throw a {@link
<i class="no-highlight">61</i>&nbsp; * ConcurrentModificationException}.  Thus, in the face of concurrent
<i class="no-highlight">62</i>&nbsp; * modification, the iterator fails quickly and cleanly, rather than
<i class="no-highlight">63</i>&nbsp; * risking arbitrary, non-deterministic behavior at an undetermined
<i class="no-highlight">64</i>&nbsp; * time in the future.
<i class="no-highlight">65</i>&nbsp; *
<i class="no-highlight">66</i>&nbsp; * &lt;p&gt;Note that the fail-fast behavior of an iterator cannot be guaranteed
<i class="no-highlight">67</i>&nbsp; * as it is, generally speaking, impossible to make any hard guarantees in the
<i class="no-highlight">68</i>&nbsp; * presence of unsynchronized concurrent modification.  Fail-fast iterators
<i class="no-highlight">69</i>&nbsp; * throw {@code ConcurrentModificationException} on a best-effort basis.
<i class="no-highlight">70</i>&nbsp; * Therefore, it would be wrong to write a program that depended on this
<i class="no-highlight">71</i>&nbsp; * exception for its correctness:   &lt;i&gt;the fail-fast behavior of iterators
<i class="no-highlight">72</i>&nbsp; * should be used only to detect bugs.&lt;/i&gt;
<i class="no-highlight">73</i>&nbsp; *
<i class="no-highlight">74</i>&nbsp; * &lt;p&gt;This class is a member of the
<i class="no-highlight">75</i>&nbsp; * &lt;a href=&quot;{@docRoot}/../technotes/guides/collections/index.html&quot;&gt;
<i class="no-highlight">76</i>&nbsp; * Java Collections Framework&lt;/a&gt;.
<i class="no-highlight">77</i>&nbsp; *
<i class="no-highlight">78</i>&nbsp; * @author  Josh Bloch
<i class="no-highlight">79</i>&nbsp; * @see     List
<i class="no-highlight">80</i>&nbsp; * @see     ArrayList
<i class="no-highlight">81</i>&nbsp; * @since 1.2
<i class="no-highlight">82</i>&nbsp; * @param &lt;E&gt; the type of elements held in this collection
<i class="no-highlight">83</i>&nbsp; */
<i class="no-highlight">84</i>&nbsp;
<b class="nc"><i class="no-highlight">85</i>&nbsp;public class LinkedList&lt;E&gt;</b>
<i class="no-highlight">86</i>&nbsp;        extends AbstractSequentialList&lt;E&gt;
<i class="no-highlight">87</i>&nbsp;        implements List&lt;E&gt;, Deque&lt;E&gt;, Cloneable, java.io.Serializable
<i class="no-highlight">88</i>&nbsp;{
<b class="fc"><i class="no-highlight">89</i>&nbsp;    transient int size = 0;</b>
<i class="no-highlight">90</i>&nbsp;
<i class="no-highlight">91</i>&nbsp;    /**
<i class="no-highlight">92</i>&nbsp;     * Pointer to first node.
<i class="no-highlight">93</i>&nbsp;     * Invariant: (first == null &amp;&amp; last == null) ||
<i class="no-highlight">94</i>&nbsp;     *            (first.prev == null &amp;&amp; first.item != null)
<i class="no-highlight">95</i>&nbsp;     */
<i class="no-highlight">96</i>&nbsp;    transient Node&lt;E&gt; first;
<i class="no-highlight">97</i>&nbsp;
<i class="no-highlight">98</i>&nbsp;    /**
<i class="no-highlight">99</i>&nbsp;     * Pointer to last node.
<i class="no-highlight">100</i>&nbsp;     * Invariant: (first == null &amp;&amp; last == null) ||
<i class="no-highlight">101</i>&nbsp;     *            (last.next == null &amp;&amp; last.item != null)
<i class="no-highlight">102</i>&nbsp;     */
<i class="no-highlight">103</i>&nbsp;    transient Node&lt;E&gt; last;
<i class="no-highlight">104</i>&nbsp;
<i class="no-highlight">105</i>&nbsp;    /**
<i class="no-highlight">106</i>&nbsp;     * Constructs an empty list.
<i class="no-highlight">107</i>&nbsp;     */
<b class="fc"><i class="no-highlight">108</i>&nbsp;    public LinkedList() {</b>
<b class="fc"><i class="no-highlight">109</i>&nbsp;    }</b>
<i class="no-highlight">110</i>&nbsp;
<i class="no-highlight">111</i>&nbsp;    /**
<i class="no-highlight">112</i>&nbsp;     * Constructs a list containing the elements of the specified
<i class="no-highlight">113</i>&nbsp;     * collection, in the order they are returned by the collection&#39;s
<i class="no-highlight">114</i>&nbsp;     * iterator.
<i class="no-highlight">115</i>&nbsp;     *
<i class="no-highlight">116</i>&nbsp;     * @param  c the collection whose elements are to be placed into this list
<i class="no-highlight">117</i>&nbsp;     * @throws NullPointerException if the specified collection is null
<i class="no-highlight">118</i>&nbsp;     */
<i class="no-highlight">119</i>&nbsp;    public LinkedList(Collection&lt;? extends E&gt; c) {
<b class="nc"><i class="no-highlight">120</i>&nbsp;        this();</b>
<b class="nc"><i class="no-highlight">121</i>&nbsp;        addAll(c);</b>
<b class="nc"><i class="no-highlight">122</i>&nbsp;    }</b>
<i class="no-highlight">123</i>&nbsp;
<i class="no-highlight">124</i>&nbsp;    /**
<i class="no-highlight">125</i>&nbsp;     * Links e as first element.
<i class="no-highlight">126</i>&nbsp;     */
<i class="no-highlight">127</i>&nbsp;    private void linkFirst(E e) {
<b class="nc"><i class="no-highlight">128</i>&nbsp;        final Node&lt;E&gt; f = first;</b>
<b class="nc"><i class="no-highlight">129</i>&nbsp;        final Node&lt;E&gt; newNode = new Node&lt;&gt;(null, e, f);</b>
<b class="nc"><i class="no-highlight">130</i>&nbsp;        first = newNode;</b>
<b class="nc"><i class="no-highlight">131</i>&nbsp;        if (f == null)</b>
<b class="nc"><i class="no-highlight">132</i>&nbsp;            last = newNode;</b>
<i class="no-highlight">133</i>&nbsp;        else
<b class="nc"><i class="no-highlight">134</i>&nbsp;            f.prev = newNode;</b>
<b class="nc"><i class="no-highlight">135</i>&nbsp;        size++;</b>
<b class="nc"><i class="no-highlight">136</i>&nbsp;        modCount++;</b>
<b class="nc"><i class="no-highlight">137</i>&nbsp;    }</b>
<i class="no-highlight">138</i>&nbsp;
<i class="no-highlight">139</i>&nbsp;    /**
<i class="no-highlight">140</i>&nbsp;     * Links e as last element.
<i class="no-highlight">141</i>&nbsp;     */
<i class="no-highlight">142</i>&nbsp;    void linkLast(E e) {
<b class="fc"><i class="no-highlight">143</i>&nbsp;        final Node&lt;E&gt; l = last;</b>
<b class="fc"><i class="no-highlight">144</i>&nbsp;        final Node&lt;E&gt; newNode = new Node&lt;&gt;(l, e, null);</b>
<b class="fc"><i class="no-highlight">145</i>&nbsp;        last = newNode;</b>
<b class="fc"><i class="no-highlight">146</i>&nbsp;        if (l == null)</b>
<b class="fc"><i class="no-highlight">147</i>&nbsp;            first = newNode;</b>
<i class="no-highlight">148</i>&nbsp;        else
<b class="fc"><i class="no-highlight">149</i>&nbsp;            l.next = newNode;</b>
<b class="fc"><i class="no-highlight">150</i>&nbsp;        size++;</b>
<b class="fc"><i class="no-highlight">151</i>&nbsp;        modCount++;</b>
<b class="fc"><i class="no-highlight">152</i>&nbsp;    }</b>
<i class="no-highlight">153</i>&nbsp;
<i class="no-highlight">154</i>&nbsp;    /**
<i class="no-highlight">155</i>&nbsp;     * Inserts element e before non-null Node succ.
<i class="no-highlight">156</i>&nbsp;     */
<i class="no-highlight">157</i>&nbsp;    void linkBefore(E e, Node&lt;E&gt; succ) {
<i class="no-highlight">158</i>&nbsp;        // assert succ != null;
<b class="nc"><i class="no-highlight">159</i>&nbsp;        final Node&lt;E&gt; pred = succ.prev;</b>
<b class="nc"><i class="no-highlight">160</i>&nbsp;        final Node&lt;E&gt; newNode = new Node&lt;&gt;(pred, e, succ);</b>
<b class="nc"><i class="no-highlight">161</i>&nbsp;        succ.prev = newNode;</b>
<b class="nc"><i class="no-highlight">162</i>&nbsp;        if (pred == null)</b>
<b class="nc"><i class="no-highlight">163</i>&nbsp;            first = newNode;</b>
<i class="no-highlight">164</i>&nbsp;        else
<b class="nc"><i class="no-highlight">165</i>&nbsp;            pred.next = newNode;</b>
<b class="nc"><i class="no-highlight">166</i>&nbsp;        size++;</b>
<b class="nc"><i class="no-highlight">167</i>&nbsp;        modCount++;</b>
<b class="nc"><i class="no-highlight">168</i>&nbsp;    }</b>
<i class="no-highlight">169</i>&nbsp;
<i class="no-highlight">170</i>&nbsp;    /**
<i class="no-highlight">171</i>&nbsp;     * Unlinks non-null first node f.
<i class="no-highlight">172</i>&nbsp;     */
<i class="no-highlight">173</i>&nbsp;    private E unlinkFirst(Node&lt;E&gt; f) {
<i class="no-highlight">174</i>&nbsp;        // assert f == first &amp;&amp; f != null;
<b class="nc"><i class="no-highlight">175</i>&nbsp;        final E element = f.item;</b>
<b class="nc"><i class="no-highlight">176</i>&nbsp;        final Node&lt;E&gt; next = f.next;</b>
<b class="nc"><i class="no-highlight">177</i>&nbsp;        f.item = null;</b>
<b class="nc"><i class="no-highlight">178</i>&nbsp;        f.next = null; // help GC</b>
<b class="nc"><i class="no-highlight">179</i>&nbsp;        first = next;</b>
<b class="nc"><i class="no-highlight">180</i>&nbsp;        if (next == null)</b>
<b class="nc"><i class="no-highlight">181</i>&nbsp;            last = null;</b>
<i class="no-highlight">182</i>&nbsp;        else
<b class="nc"><i class="no-highlight">183</i>&nbsp;            next.prev = null;</b>
<b class="nc"><i class="no-highlight">184</i>&nbsp;        size--;</b>
<b class="nc"><i class="no-highlight">185</i>&nbsp;        modCount++;</b>
<b class="nc"><i class="no-highlight">186</i>&nbsp;        return element;</b>
<i class="no-highlight">187</i>&nbsp;    }
<i class="no-highlight">188</i>&nbsp;
<i class="no-highlight">189</i>&nbsp;    /**
<i class="no-highlight">190</i>&nbsp;     * Unlinks non-null last node l.
<i class="no-highlight">191</i>&nbsp;     */
<i class="no-highlight">192</i>&nbsp;    private E unlinkLast(Node&lt;E&gt; l) {
<i class="no-highlight">193</i>&nbsp;        // assert l == last &amp;&amp; l != null;
<b class="nc"><i class="no-highlight">194</i>&nbsp;        final E element = l.item;</b>
<b class="nc"><i class="no-highlight">195</i>&nbsp;        final Node&lt;E&gt; prev = l.prev;</b>
<b class="nc"><i class="no-highlight">196</i>&nbsp;        l.item = null;</b>
<b class="nc"><i class="no-highlight">197</i>&nbsp;        l.prev = null; // help GC</b>
<b class="nc"><i class="no-highlight">198</i>&nbsp;        last = prev;</b>
<b class="nc"><i class="no-highlight">199</i>&nbsp;        if (prev == null)</b>
<b class="nc"><i class="no-highlight">200</i>&nbsp;            first = null;</b>
<i class="no-highlight">201</i>&nbsp;        else
<b class="nc"><i class="no-highlight">202</i>&nbsp;            prev.next = null;</b>
<b class="nc"><i class="no-highlight">203</i>&nbsp;        size--;</b>
<b class="nc"><i class="no-highlight">204</i>&nbsp;        modCount++;</b>
<b class="nc"><i class="no-highlight">205</i>&nbsp;        return element;</b>
<i class="no-highlight">206</i>&nbsp;    }
<i class="no-highlight">207</i>&nbsp;
<i class="no-highlight">208</i>&nbsp;    /**
<i class="no-highlight">209</i>&nbsp;     * Unlinks non-null node x.
<i class="no-highlight">210</i>&nbsp;     */
<i class="no-highlight">211</i>&nbsp;    E unlink(Node&lt;E&gt; x) {
<i class="no-highlight">212</i>&nbsp;        // assert x != null;
<b class="fc"><i class="no-highlight">213</i>&nbsp;        final E element = x.item;</b>
<b class="fc"><i class="no-highlight">214</i>&nbsp;        final Node&lt;E&gt; next = x.next;</b>
<b class="fc"><i class="no-highlight">215</i>&nbsp;        final Node&lt;E&gt; prev = x.prev;</b>
<i class="no-highlight">216</i>&nbsp;
<b class="fc"><i class="no-highlight">217</i>&nbsp;        if (prev == null) {</b>
<b class="nc"><i class="no-highlight">218</i>&nbsp;            first = next;</b>
<i class="no-highlight">219</i>&nbsp;        } else {
<b class="fc"><i class="no-highlight">220</i>&nbsp;            prev.next = next;</b>
<b class="fc"><i class="no-highlight">221</i>&nbsp;            x.prev = null;</b>
<i class="no-highlight">222</i>&nbsp;        }
<i class="no-highlight">223</i>&nbsp;
<b class="fc"><i class="no-highlight">224</i>&nbsp;        if (next == null) {</b>
<b class="nc"><i class="no-highlight">225</i>&nbsp;            last = prev;</b>
<i class="no-highlight">226</i>&nbsp;        } else {
<b class="fc"><i class="no-highlight">227</i>&nbsp;            next.prev = prev;</b>
<b class="fc"><i class="no-highlight">228</i>&nbsp;            x.next = null;</b>
<i class="no-highlight">229</i>&nbsp;        }
<i class="no-highlight">230</i>&nbsp;
<b class="fc"><i class="no-highlight">231</i>&nbsp;        x.item = null;</b>
<b class="fc"><i class="no-highlight">232</i>&nbsp;        size--;</b>
<b class="fc"><i class="no-highlight">233</i>&nbsp;        modCount++;</b>
<b class="fc"><i class="no-highlight">234</i>&nbsp;        return element;</b>
<i class="no-highlight">235</i>&nbsp;    }
<i class="no-highlight">236</i>&nbsp;
<i class="no-highlight">237</i>&nbsp;    /**
<i class="no-highlight">238</i>&nbsp;     * Returns the first element in this list.
<i class="no-highlight">239</i>&nbsp;     *
<i class="no-highlight">240</i>&nbsp;     * @return the first element in this list
<i class="no-highlight">241</i>&nbsp;     * @throws NoSuchElementException if this list is empty
<i class="no-highlight">242</i>&nbsp;     */
<i class="no-highlight">243</i>&nbsp;    public E getFirst() {
<b class="nc"><i class="no-highlight">244</i>&nbsp;        final Node&lt;E&gt; f = first;</b>
<b class="nc"><i class="no-highlight">245</i>&nbsp;        if (f == null)</b>
<b class="nc"><i class="no-highlight">246</i>&nbsp;            throw new NoSuchElementException();</b>
<b class="nc"><i class="no-highlight">247</i>&nbsp;        return f.item;</b>
<i class="no-highlight">248</i>&nbsp;    }
<i class="no-highlight">249</i>&nbsp;
<i class="no-highlight">250</i>&nbsp;    /**
<i class="no-highlight">251</i>&nbsp;     * Returns the last element in this list.
<i class="no-highlight">252</i>&nbsp;     *
<i class="no-highlight">253</i>&nbsp;     * @return the last element in this list
<i class="no-highlight">254</i>&nbsp;     * @throws NoSuchElementException if this list is empty
<i class="no-highlight">255</i>&nbsp;     */
<i class="no-highlight">256</i>&nbsp;    public E getLast() {
<b class="nc"><i class="no-highlight">257</i>&nbsp;        final Node&lt;E&gt; l = last;</b>
<b class="nc"><i class="no-highlight">258</i>&nbsp;        if (l == null)</b>
<b class="nc"><i class="no-highlight">259</i>&nbsp;            throw new NoSuchElementException();</b>
<b class="nc"><i class="no-highlight">260</i>&nbsp;        return l.item;</b>
<i class="no-highlight">261</i>&nbsp;    }
<i class="no-highlight">262</i>&nbsp;
<i class="no-highlight">263</i>&nbsp;    /**
<i class="no-highlight">264</i>&nbsp;     * Removes and returns the first element from this list.
<i class="no-highlight">265</i>&nbsp;     *
<i class="no-highlight">266</i>&nbsp;     * @return the first element from this list
<i class="no-highlight">267</i>&nbsp;     * @throws NoSuchElementException if this list is empty
<i class="no-highlight">268</i>&nbsp;     */
<i class="no-highlight">269</i>&nbsp;    public E removeFirst() {
<b class="nc"><i class="no-highlight">270</i>&nbsp;        final Node&lt;E&gt; f = first;</b>
<b class="nc"><i class="no-highlight">271</i>&nbsp;        if (f == null)</b>
<b class="nc"><i class="no-highlight">272</i>&nbsp;            throw new NoSuchElementException();</b>
<b class="nc"><i class="no-highlight">273</i>&nbsp;        return unlinkFirst(f);</b>
<i class="no-highlight">274</i>&nbsp;    }
<i class="no-highlight">275</i>&nbsp;
<i class="no-highlight">276</i>&nbsp;    /**
<i class="no-highlight">277</i>&nbsp;     * Removes and returns the last element from this list.
<i class="no-highlight">278</i>&nbsp;     *
<i class="no-highlight">279</i>&nbsp;     * @return the last element from this list
<i class="no-highlight">280</i>&nbsp;     * @throws NoSuchElementException if this list is empty
<i class="no-highlight">281</i>&nbsp;     */
<i class="no-highlight">282</i>&nbsp;    public E removeLast() {
<b class="nc"><i class="no-highlight">283</i>&nbsp;        final Node&lt;E&gt; l = last;</b>
<b class="nc"><i class="no-highlight">284</i>&nbsp;        if (l == null)</b>
<b class="nc"><i class="no-highlight">285</i>&nbsp;            throw new NoSuchElementException();</b>
<b class="nc"><i class="no-highlight">286</i>&nbsp;        return unlinkLast(l);</b>
<i class="no-highlight">287</i>&nbsp;    }
<i class="no-highlight">288</i>&nbsp;
<i class="no-highlight">289</i>&nbsp;    /**
<i class="no-highlight">290</i>&nbsp;     * Inserts the specified element at the beginning of this list.
<i class="no-highlight">291</i>&nbsp;     *
<i class="no-highlight">292</i>&nbsp;     * @param e the element to add
<i class="no-highlight">293</i>&nbsp;     */
<i class="no-highlight">294</i>&nbsp;    public void addFirst(E e) {
<b class="nc"><i class="no-highlight">295</i>&nbsp;        linkFirst(e);</b>
<b class="nc"><i class="no-highlight">296</i>&nbsp;    }</b>
<i class="no-highlight">297</i>&nbsp;
<i class="no-highlight">298</i>&nbsp;    /**
<i class="no-highlight">299</i>&nbsp;     * Appends the specified element to the end of this list.
<i class="no-highlight">300</i>&nbsp;     *
<i class="no-highlight">301</i>&nbsp;     * &lt;p&gt;This method is equivalent to {@link #add}.
<i class="no-highlight">302</i>&nbsp;     *
<i class="no-highlight">303</i>&nbsp;     * @param e the element to add
<i class="no-highlight">304</i>&nbsp;     */
<i class="no-highlight">305</i>&nbsp;    public void addLast(E e) {
<b class="nc"><i class="no-highlight">306</i>&nbsp;        linkLast(e);</b>
<b class="nc"><i class="no-highlight">307</i>&nbsp;    }</b>
<i class="no-highlight">308</i>&nbsp;
<i class="no-highlight">309</i>&nbsp;    /**
<i class="no-highlight">310</i>&nbsp;     * Returns {@code true} if this list contains the specified element.
<i class="no-highlight">311</i>&nbsp;     * More formally, returns {@code true} if and only if this list contains
<i class="no-highlight">312</i>&nbsp;     * at least one element {@code e} such that
<i class="no-highlight">313</i>&nbsp;     * &lt;tt&gt;(o==null&amp;nbsp;?&amp;nbsp;e==null&amp;nbsp;:&amp;nbsp;o.equals(e))&lt;/tt&gt;.
<i class="no-highlight">314</i>&nbsp;     *
<i class="no-highlight">315</i>&nbsp;     * @param o element whose presence in this list is to be tested
<i class="no-highlight">316</i>&nbsp;     * @return {@code true} if this list contains the specified element
<i class="no-highlight">317</i>&nbsp;     */
<i class="no-highlight">318</i>&nbsp;    public boolean contains(Object o) {
<b class="nc"><i class="no-highlight">319</i>&nbsp;        return indexOf(o) != -1;</b>
<i class="no-highlight">320</i>&nbsp;    }
<i class="no-highlight">321</i>&nbsp;
<i class="no-highlight">322</i>&nbsp;    /**
<i class="no-highlight">323</i>&nbsp;     * Returns the number of elements in this list.
<i class="no-highlight">324</i>&nbsp;     *
<i class="no-highlight">325</i>&nbsp;     * @return the number of elements in this list
<i class="no-highlight">326</i>&nbsp;     */
<i class="no-highlight">327</i>&nbsp;    public int size() {
<b class="nc"><i class="no-highlight">328</i>&nbsp;        return size;</b>
<i class="no-highlight">329</i>&nbsp;    }
<i class="no-highlight">330</i>&nbsp;
<i class="no-highlight">331</i>&nbsp;    /**
<i class="no-highlight">332</i>&nbsp;     * Appends the specified element to the end of this list.
<i class="no-highlight">333</i>&nbsp;     *
<i class="no-highlight">334</i>&nbsp;     * &lt;p&gt;This method is equivalent to {@link #addLast}.
<i class="no-highlight">335</i>&nbsp;     *
<i class="no-highlight">336</i>&nbsp;     * @param e element to be appended to this list
<i class="no-highlight">337</i>&nbsp;     * @return {@code true} (as specified by {@link Collection#add})
<i class="no-highlight">338</i>&nbsp;     */
<i class="no-highlight">339</i>&nbsp;    public boolean add(E e) {
<b class="fc"><i class="no-highlight">340</i>&nbsp;        linkLast(e);</b>
<b class="fc"><i class="no-highlight">341</i>&nbsp;        return true;</b>
<i class="no-highlight">342</i>&nbsp;    }
<i class="no-highlight">343</i>&nbsp;
<i class="no-highlight">344</i>&nbsp;    /**
<i class="no-highlight">345</i>&nbsp;     * Removes the first occurrence of the specified element from this list,
<i class="no-highlight">346</i>&nbsp;     * if it is present.  If this list does not contain the element, it is
<i class="no-highlight">347</i>&nbsp;     * unchanged.  More formally, removes the element with the lowest index
<i class="no-highlight">348</i>&nbsp;     * {@code i} such that
<i class="no-highlight">349</i>&nbsp;     * &lt;tt&gt;(o==null&amp;nbsp;?&amp;nbsp;get(i)==null&amp;nbsp;:&amp;nbsp;o.equals(get(i)))&lt;/tt&gt;
<i class="no-highlight">350</i>&nbsp;     * (if such an element exists).  Returns {@code true} if this list
<i class="no-highlight">351</i>&nbsp;     * contained the specified element (or equivalently, if this list
<i class="no-highlight">352</i>&nbsp;     * changed as a result of the call).
<i class="no-highlight">353</i>&nbsp;     *
<i class="no-highlight">354</i>&nbsp;     * @param o element to be removed from this list, if present
<i class="no-highlight">355</i>&nbsp;     * @return {@code true} if this list contained the specified element
<i class="no-highlight">356</i>&nbsp;     */
<i class="no-highlight">357</i>&nbsp;    public boolean remove(Object o) {
<b class="fc"><i class="no-highlight">358</i>&nbsp;        if (o == null) {</b>
<b class="fc"><i class="no-highlight">359</i>&nbsp;            for (Node&lt;E&gt; x = first; x != null; x = x.next) {</b>
<b class="fc"><i class="no-highlight">360</i>&nbsp;                if (x.item == null) {</b>
<b class="fc"><i class="no-highlight">361</i>&nbsp;                    unlink(x);</b>
<b class="fc"><i class="no-highlight">362</i>&nbsp;                    return true;</b>
<i class="no-highlight">363</i>&nbsp;                }
<i class="no-highlight">364</i>&nbsp;            }
<i class="no-highlight">365</i>&nbsp;        } else {
<b class="fc"><i class="no-highlight">366</i>&nbsp;            for (Node&lt;E&gt; x = first; x != null; x = x.next) {</b>
<b class="fc"><i class="no-highlight">367</i>&nbsp;                if (o.equals(x.item)) {</b>
<b class="fc"><i class="no-highlight">368</i>&nbsp;                    unlink(x);</b>
<b class="fc"><i class="no-highlight">369</i>&nbsp;                    return true;</b>
<i class="no-highlight">370</i>&nbsp;                }
<i class="no-highlight">371</i>&nbsp;            }
<i class="no-highlight">372</i>&nbsp;        }
<b class="fc"><i class="no-highlight">373</i>&nbsp;        return false;</b>
<i class="no-highlight">374</i>&nbsp;    }
<i class="no-highlight">375</i>&nbsp;
<i class="no-highlight">376</i>&nbsp;    /**
<i class="no-highlight">377</i>&nbsp;     * Appends all of the elements in the specified collection to the end of
<i class="no-highlight">378</i>&nbsp;     * this list, in the order that they are returned by the specified
<i class="no-highlight">379</i>&nbsp;     * collection&#39;s iterator.  The behavior of this operation is undefined if
<i class="no-highlight">380</i>&nbsp;     * the specified collection is modified while the operation is in
<i class="no-highlight">381</i>&nbsp;     * progress.  (Note that this will occur if the specified collection is
<i class="no-highlight">382</i>&nbsp;     * this list, and it&#39;s nonempty.)
<i class="no-highlight">383</i>&nbsp;     *
<i class="no-highlight">384</i>&nbsp;     * @param c collection containing elements to be added to this list
<i class="no-highlight">385</i>&nbsp;     * @return {@code true} if this list changed as a result of the call
<i class="no-highlight">386</i>&nbsp;     * @throws NullPointerException if the specified collection is null
<i class="no-highlight">387</i>&nbsp;     */
<i class="no-highlight">388</i>&nbsp;    public boolean addAll(Collection&lt;? extends E&gt; c) {
<b class="nc"><i class="no-highlight">389</i>&nbsp;        return addAll(size, c);</b>
<i class="no-highlight">390</i>&nbsp;    }
<i class="no-highlight">391</i>&nbsp;
<i class="no-highlight">392</i>&nbsp;    /**
<i class="no-highlight">393</i>&nbsp;     * Inserts all of the elements in the specified collection into this
<i class="no-highlight">394</i>&nbsp;     * list, starting at the specified position.  Shifts the element
<i class="no-highlight">395</i>&nbsp;     * currently at that position (if any) and any subsequent elements to
<i class="no-highlight">396</i>&nbsp;     * the right (increases their indices).  The new elements will appear
<i class="no-highlight">397</i>&nbsp;     * in the list in the order that they are returned by the
<i class="no-highlight">398</i>&nbsp;     * specified collection&#39;s iterator.
<i class="no-highlight">399</i>&nbsp;     *
<i class="no-highlight">400</i>&nbsp;     * @param index index at which to insert the first element
<i class="no-highlight">401</i>&nbsp;     *              from the specified collection
<i class="no-highlight">402</i>&nbsp;     * @param c collection containing elements to be added to this list
<i class="no-highlight">403</i>&nbsp;     * @return {@code true} if this list changed as a result of the call
<i class="no-highlight">404</i>&nbsp;     * @throws IndexOutOfBoundsException {@inheritDoc}
<i class="no-highlight">405</i>&nbsp;     * @throws NullPointerException if the specified collection is null
<i class="no-highlight">406</i>&nbsp;     */
<i class="no-highlight">407</i>&nbsp;    public boolean addAll(int index, Collection&lt;? extends E&gt; c) {
<b class="nc"><i class="no-highlight">408</i>&nbsp;        checkPositionIndex(index);</b>
<i class="no-highlight">409</i>&nbsp;
<b class="nc"><i class="no-highlight">410</i>&nbsp;        Object[] a = c.toArray();</b>
<b class="nc"><i class="no-highlight">411</i>&nbsp;        int numNew = a.length;</b>
<b class="nc"><i class="no-highlight">412</i>&nbsp;        if (numNew == 0)</b>
<b class="nc"><i class="no-highlight">413</i>&nbsp;            return false;</b>
<i class="no-highlight">414</i>&nbsp;
<i class="no-highlight">415</i>&nbsp;        Node&lt;E&gt; pred, succ;
<b class="nc"><i class="no-highlight">416</i>&nbsp;        if (index == size) {</b>
<b class="nc"><i class="no-highlight">417</i>&nbsp;            succ = null;</b>
<b class="nc"><i class="no-highlight">418</i>&nbsp;            pred = last;</b>
<i class="no-highlight">419</i>&nbsp;        } else {
<b class="nc"><i class="no-highlight">420</i>&nbsp;            succ = node(index);</b>
<b class="nc"><i class="no-highlight">421</i>&nbsp;            pred = succ.prev;</b>
<i class="no-highlight">422</i>&nbsp;        }
<i class="no-highlight">423</i>&nbsp;
<b class="nc"><i class="no-highlight">424</i>&nbsp;        for (Object o : a) {</b>
<b class="nc"><i class="no-highlight">425</i>&nbsp;            @SuppressWarnings(&quot;unchecked&quot;) E e = (E) o;</b>
<b class="nc"><i class="no-highlight">426</i>&nbsp;            Node&lt;E&gt; newNode = new Node&lt;&gt;(pred, e, null);</b>
<b class="nc"><i class="no-highlight">427</i>&nbsp;            if (pred == null)</b>
<b class="nc"><i class="no-highlight">428</i>&nbsp;                first = newNode;</b>
<i class="no-highlight">429</i>&nbsp;            else
<b class="nc"><i class="no-highlight">430</i>&nbsp;                pred.next = newNode;</b>
<b class="nc"><i class="no-highlight">431</i>&nbsp;            pred = newNode;</b>
<i class="no-highlight">432</i>&nbsp;        }
<i class="no-highlight">433</i>&nbsp;
<b class="nc"><i class="no-highlight">434</i>&nbsp;        if (succ == null) {</b>
<b class="nc"><i class="no-highlight">435</i>&nbsp;            last = pred;</b>
<i class="no-highlight">436</i>&nbsp;        } else {
<b class="nc"><i class="no-highlight">437</i>&nbsp;            pred.next = succ;</b>
<b class="nc"><i class="no-highlight">438</i>&nbsp;            succ.prev = pred;</b>
<i class="no-highlight">439</i>&nbsp;        }
<i class="no-highlight">440</i>&nbsp;
<b class="nc"><i class="no-highlight">441</i>&nbsp;        size += numNew;</b>
<b class="nc"><i class="no-highlight">442</i>&nbsp;        modCount++;</b>
<b class="nc"><i class="no-highlight">443</i>&nbsp;        return true;</b>
<i class="no-highlight">444</i>&nbsp;    }
<i class="no-highlight">445</i>&nbsp;
<i class="no-highlight">446</i>&nbsp;    /**
<i class="no-highlight">447</i>&nbsp;     * Removes all of the elements from this list.
<i class="no-highlight">448</i>&nbsp;     * The list will be empty after this call returns.
<i class="no-highlight">449</i>&nbsp;     */
<i class="no-highlight">450</i>&nbsp;    public void clear() {
<i class="no-highlight">451</i>&nbsp;        // Clearing all of the links between nodes is &quot;unnecessary&quot;, but:
<i class="no-highlight">452</i>&nbsp;        // - helps a generational GC if the discarded nodes inhabit
<i class="no-highlight">453</i>&nbsp;        //   more than one generation
<i class="no-highlight">454</i>&nbsp;        // - is sure to free memory even if there is a reachable Iterator
<b class="nc"><i class="no-highlight">455</i>&nbsp;        for (Node&lt;E&gt; x = first; x != null; ) {</b>
<b class="nc"><i class="no-highlight">456</i>&nbsp;            Node&lt;E&gt; next = x.next;</b>
<b class="nc"><i class="no-highlight">457</i>&nbsp;            x.item = null;</b>
<b class="nc"><i class="no-highlight">458</i>&nbsp;            x.next = null;</b>
<b class="nc"><i class="no-highlight">459</i>&nbsp;            x.prev = null;</b>
<b class="nc"><i class="no-highlight">460</i>&nbsp;            x = next;</b>
<b class="nc"><i class="no-highlight">461</i>&nbsp;        }</b>
<b class="nc"><i class="no-highlight">462</i>&nbsp;        first = last = null;</b>
<b class="nc"><i class="no-highlight">463</i>&nbsp;        size = 0;</b>
<b class="nc"><i class="no-highlight">464</i>&nbsp;        modCount++;</b>
<b class="nc"><i class="no-highlight">465</i>&nbsp;    }</b>
<i class="no-highlight">466</i>&nbsp;
<i class="no-highlight">467</i>&nbsp;
<i class="no-highlight">468</i>&nbsp;    // Positional Access Operations
<i class="no-highlight">469</i>&nbsp;
<i class="no-highlight">470</i>&nbsp;    /**
<i class="no-highlight">471</i>&nbsp;     * Returns the element at the specified position in this list.
<i class="no-highlight">472</i>&nbsp;     *
<i class="no-highlight">473</i>&nbsp;     * @param index index of the element to return
<i class="no-highlight">474</i>&nbsp;     * @return the element at the specified position in this list
<i class="no-highlight">475</i>&nbsp;     * @throws IndexOutOfBoundsException {@inheritDoc}
<i class="no-highlight">476</i>&nbsp;     */
<i class="no-highlight">477</i>&nbsp;    public E get(int index) {
<b class="nc"><i class="no-highlight">478</i>&nbsp;        checkElementIndex(index);</b>
<b class="nc"><i class="no-highlight">479</i>&nbsp;        return node(index).item;</b>
<i class="no-highlight">480</i>&nbsp;    }
<i class="no-highlight">481</i>&nbsp;
<i class="no-highlight">482</i>&nbsp;    /**
<i class="no-highlight">483</i>&nbsp;     * Replaces the element at the specified position in this list with the
<i class="no-highlight">484</i>&nbsp;     * specified element.
<i class="no-highlight">485</i>&nbsp;     *
<i class="no-highlight">486</i>&nbsp;     * @param index index of the element to replace
<i class="no-highlight">487</i>&nbsp;     * @param element element to be stored at the specified position
<i class="no-highlight">488</i>&nbsp;     * @return the element previously at the specified position
<i class="no-highlight">489</i>&nbsp;     * @throws IndexOutOfBoundsException {@inheritDoc}
<i class="no-highlight">490</i>&nbsp;     */
<i class="no-highlight">491</i>&nbsp;    public E set(int index, E element) {
<b class="nc"><i class="no-highlight">492</i>&nbsp;        checkElementIndex(index);</b>
<b class="nc"><i class="no-highlight">493</i>&nbsp;        Node&lt;E&gt; x = node(index);</b>
<b class="nc"><i class="no-highlight">494</i>&nbsp;        E oldVal = x.item;</b>
<b class="nc"><i class="no-highlight">495</i>&nbsp;        x.item = element;</b>
<b class="nc"><i class="no-highlight">496</i>&nbsp;        return oldVal;</b>
<i class="no-highlight">497</i>&nbsp;    }
<i class="no-highlight">498</i>&nbsp;
<i class="no-highlight">499</i>&nbsp;    /**
<i class="no-highlight">500</i>&nbsp;     * Inserts the specified element at the specified position in this list.
<i class="no-highlight">501</i>&nbsp;     * Shifts the element currently at that position (if any) and any
<i class="no-highlight">502</i>&nbsp;     * subsequent elements to the right (adds one to their indices).
<i class="no-highlight">503</i>&nbsp;     *
<i class="no-highlight">504</i>&nbsp;     * @param index index at which the specified element is to be inserted
<i class="no-highlight">505</i>&nbsp;     * @param element element to be inserted
<i class="no-highlight">506</i>&nbsp;     * @throws IndexOutOfBoundsException {@inheritDoc}
<i class="no-highlight">507</i>&nbsp;     */
<i class="no-highlight">508</i>&nbsp;    public void add(int index, E element) {
<b class="nc"><i class="no-highlight">509</i>&nbsp;        checkPositionIndex(index);</b>
<i class="no-highlight">510</i>&nbsp;
<b class="nc"><i class="no-highlight">511</i>&nbsp;        if (index == size)</b>
<b class="nc"><i class="no-highlight">512</i>&nbsp;            linkLast(element);</b>
<i class="no-highlight">513</i>&nbsp;        else
<b class="nc"><i class="no-highlight">514</i>&nbsp;            linkBefore(element, node(index));</b>
<b class="nc"><i class="no-highlight">515</i>&nbsp;    }</b>
<i class="no-highlight">516</i>&nbsp;
<i class="no-highlight">517</i>&nbsp;    /**
<i class="no-highlight">518</i>&nbsp;     * Removes the element at the specified position in this list.  Shifts any
<i class="no-highlight">519</i>&nbsp;     * subsequent elements to the left (subtracts one from their indices).
<i class="no-highlight">520</i>&nbsp;     * Returns the element that was removed from the list.
<i class="no-highlight">521</i>&nbsp;     *
<i class="no-highlight">522</i>&nbsp;     * @param index the index of the element to be removed
<i class="no-highlight">523</i>&nbsp;     * @return the element previously at the specified position
<i class="no-highlight">524</i>&nbsp;     * @throws IndexOutOfBoundsException {@inheritDoc}
<i class="no-highlight">525</i>&nbsp;     */
<i class="no-highlight">526</i>&nbsp;    public E remove(int index) {
<b class="nc"><i class="no-highlight">527</i>&nbsp;        checkElementIndex(index);</b>
<b class="nc"><i class="no-highlight">528</i>&nbsp;        return unlink(node(index));</b>
<i class="no-highlight">529</i>&nbsp;    }
<i class="no-highlight">530</i>&nbsp;
<i class="no-highlight">531</i>&nbsp;    /**
<i class="no-highlight">532</i>&nbsp;     * Tells if the argument is the index of an existing element.
<i class="no-highlight">533</i>&nbsp;     */
<i class="no-highlight">534</i>&nbsp;    private boolean isElementIndex(int index) {
<b class="nc"><i class="no-highlight">535</i>&nbsp;        return index &gt;= 0 &amp;&amp; index &lt; size;</b>
<i class="no-highlight">536</i>&nbsp;    }
<i class="no-highlight">537</i>&nbsp;
<i class="no-highlight">538</i>&nbsp;    /**
<i class="no-highlight">539</i>&nbsp;     * Tells if the argument is the index of a valid position for an
<i class="no-highlight">540</i>&nbsp;     * iterator or an add operation.
<i class="no-highlight">541</i>&nbsp;     */
<i class="no-highlight">542</i>&nbsp;    private boolean isPositionIndex(int index) {
<b class="nc"><i class="no-highlight">543</i>&nbsp;        return index &gt;= 0 &amp;&amp; index &lt;= size;</b>
<i class="no-highlight">544</i>&nbsp;    }
<i class="no-highlight">545</i>&nbsp;
<i class="no-highlight">546</i>&nbsp;    /**
<i class="no-highlight">547</i>&nbsp;     * Constructs an IndexOutOfBoundsException detail message.
<i class="no-highlight">548</i>&nbsp;     * Of the many possible refactorings of the error handling code,
<i class="no-highlight">549</i>&nbsp;     * this &quot;outlining&quot; performs best with both server and client VMs.
<i class="no-highlight">550</i>&nbsp;     */
<i class="no-highlight">551</i>&nbsp;    private String outOfBoundsMsg(int index) {
<b class="nc"><i class="no-highlight">552</i>&nbsp;        return &quot;Index: &quot;+index+&quot;, Size: &quot;+size;</b>
<i class="no-highlight">553</i>&nbsp;    }
<i class="no-highlight">554</i>&nbsp;
<i class="no-highlight">555</i>&nbsp;    private void checkElementIndex(int index) {
<b class="nc"><i class="no-highlight">556</i>&nbsp;        if (!isElementIndex(index))</b>
<b class="nc"><i class="no-highlight">557</i>&nbsp;            throw new IndexOutOfBoundsException(outOfBoundsMsg(index));</b>
<b class="nc"><i class="no-highlight">558</i>&nbsp;    }</b>
<i class="no-highlight">559</i>&nbsp;
<i class="no-highlight">560</i>&nbsp;    private void checkPositionIndex(int index) {
<b class="nc"><i class="no-highlight">561</i>&nbsp;        if (!isPositionIndex(index))</b>
<b class="nc"><i class="no-highlight">562</i>&nbsp;            throw new IndexOutOfBoundsException(outOfBoundsMsg(index));</b>
<b class="nc"><i class="no-highlight">563</i>&nbsp;    }</b>
<i class="no-highlight">564</i>&nbsp;
<i class="no-highlight">565</i>&nbsp;    /**
<i class="no-highlight">566</i>&nbsp;     * Returns the (non-null) Node at the specified element index.
<i class="no-highlight">567</i>&nbsp;     */
<i class="no-highlight">568</i>&nbsp;    Node&lt;E&gt; node(int index) {
<i class="no-highlight">569</i>&nbsp;        // assert isElementIndex(index);
<i class="no-highlight">570</i>&nbsp;
<b class="nc"><i class="no-highlight">571</i>&nbsp;        if (index &lt; (size &gt;&gt; 1)) {</b>
<b class="nc"><i class="no-highlight">572</i>&nbsp;            Node&lt;E&gt; x = first;</b>
<b class="nc"><i class="no-highlight">573</i>&nbsp;            for (int i = 0; i &lt; index; i++)</b>
<b class="nc"><i class="no-highlight">574</i>&nbsp;                x = x.next;</b>
<b class="nc"><i class="no-highlight">575</i>&nbsp;            return x;</b>
<i class="no-highlight">576</i>&nbsp;        } else {
<b class="nc"><i class="no-highlight">577</i>&nbsp;            Node&lt;E&gt; x = last;</b>
<b class="nc"><i class="no-highlight">578</i>&nbsp;            for (int i = size - 1; i &gt; index; i--)</b>
<b class="nc"><i class="no-highlight">579</i>&nbsp;                x = x.prev;</b>
<b class="nc"><i class="no-highlight">580</i>&nbsp;            return x;</b>
<i class="no-highlight">581</i>&nbsp;        }
<i class="no-highlight">582</i>&nbsp;    }
<i class="no-highlight">583</i>&nbsp;
<i class="no-highlight">584</i>&nbsp;    // Search Operations
<i class="no-highlight">585</i>&nbsp;
<i class="no-highlight">586</i>&nbsp;    /**
<i class="no-highlight">587</i>&nbsp;     * Returns the index of the first occurrence of the specified element
<i class="no-highlight">588</i>&nbsp;     * in this list, or -1 if this list does not contain the element.
<i class="no-highlight">589</i>&nbsp;     * More formally, returns the lowest index {@code i} such that
<i class="no-highlight">590</i>&nbsp;     * &lt;tt&gt;(o==null&amp;nbsp;?&amp;nbsp;get(i)==null&amp;nbsp;:&amp;nbsp;o.equals(get(i)))&lt;/tt&gt;,
<i class="no-highlight">591</i>&nbsp;     * or -1 if there is no such index.
<i class="no-highlight">592</i>&nbsp;     *
<i class="no-highlight">593</i>&nbsp;     * @param o element to search for
<i class="no-highlight">594</i>&nbsp;     * @return the index of the first occurrence of the specified element in
<i class="no-highlight">595</i>&nbsp;     *         this list, or -1 if this list does not contain the element
<i class="no-highlight">596</i>&nbsp;     */
<i class="no-highlight">597</i>&nbsp;    public int indexOf(Object o) {
<b class="nc"><i class="no-highlight">598</i>&nbsp;        int index = 0;</b>
<b class="nc"><i class="no-highlight">599</i>&nbsp;        if (o == null) {</b>
<b class="nc"><i class="no-highlight">600</i>&nbsp;            for (Node&lt;E&gt; x = first; x != null; x = x.next) {</b>
<b class="nc"><i class="no-highlight">601</i>&nbsp;                if (x.item == null)</b>
<b class="nc"><i class="no-highlight">602</i>&nbsp;                    return index;</b>
<b class="nc"><i class="no-highlight">603</i>&nbsp;                index++;</b>
<i class="no-highlight">604</i>&nbsp;            }
<i class="no-highlight">605</i>&nbsp;        } else {
<b class="nc"><i class="no-highlight">606</i>&nbsp;            for (Node&lt;E&gt; x = first; x != null; x = x.next) {</b>
<b class="nc"><i class="no-highlight">607</i>&nbsp;                if (o.equals(x.item))</b>
<b class="nc"><i class="no-highlight">608</i>&nbsp;                    return index;</b>
<b class="nc"><i class="no-highlight">609</i>&nbsp;                index++;</b>
<i class="no-highlight">610</i>&nbsp;            }
<i class="no-highlight">611</i>&nbsp;        }
<b class="nc"><i class="no-highlight">612</i>&nbsp;        return -1;</b>
<i class="no-highlight">613</i>&nbsp;    }
<i class="no-highlight">614</i>&nbsp;
<i class="no-highlight">615</i>&nbsp;    /**
<i class="no-highlight">616</i>&nbsp;     * Returns the index of the last occurrence of the specified element
<i class="no-highlight">617</i>&nbsp;     * in this list, or -1 if this list does not contain the element.
<i class="no-highlight">618</i>&nbsp;     * More formally, returns the highest index {@code i} such that
<i class="no-highlight">619</i>&nbsp;     * &lt;tt&gt;(o==null&amp;nbsp;?&amp;nbsp;get(i)==null&amp;nbsp;:&amp;nbsp;o.equals(get(i)))&lt;/tt&gt;,
<i class="no-highlight">620</i>&nbsp;     * or -1 if there is no such index.
<i class="no-highlight">621</i>&nbsp;     *
<i class="no-highlight">622</i>&nbsp;     * @param o element to search for
<i class="no-highlight">623</i>&nbsp;     * @return the index of the last occurrence of the specified element in
<i class="no-highlight">624</i>&nbsp;     *         this list, or -1 if this list does not contain the element
<i class="no-highlight">625</i>&nbsp;     */
<i class="no-highlight">626</i>&nbsp;    public int lastIndexOf(Object o) {
<b class="nc"><i class="no-highlight">627</i>&nbsp;        int index = size;</b>
<b class="nc"><i class="no-highlight">628</i>&nbsp;        if (o == null) {</b>
<b class="nc"><i class="no-highlight">629</i>&nbsp;            for (Node&lt;E&gt; x = last; x != null; x = x.prev) {</b>
<b class="nc"><i class="no-highlight">630</i>&nbsp;                index--;</b>
<b class="nc"><i class="no-highlight">631</i>&nbsp;                if (x.item == null)</b>
<b class="nc"><i class="no-highlight">632</i>&nbsp;                    return index;</b>
<i class="no-highlight">633</i>&nbsp;            }
<i class="no-highlight">634</i>&nbsp;        } else {
<b class="nc"><i class="no-highlight">635</i>&nbsp;            for (Node&lt;E&gt; x = last; x != null; x = x.prev) {</b>
<b class="nc"><i class="no-highlight">636</i>&nbsp;                index--;</b>
<b class="nc"><i class="no-highlight">637</i>&nbsp;                if (o.equals(x.item))</b>
<b class="nc"><i class="no-highlight">638</i>&nbsp;                    return index;</b>
<i class="no-highlight">639</i>&nbsp;            }
<i class="no-highlight">640</i>&nbsp;        }
<b class="nc"><i class="no-highlight">641</i>&nbsp;        return -1;</b>
<i class="no-highlight">642</i>&nbsp;    }
<i class="no-highlight">643</i>&nbsp;
<i class="no-highlight">644</i>&nbsp;    // Queue operations.
<i class="no-highlight">645</i>&nbsp;
<i class="no-highlight">646</i>&nbsp;    /**
<i class="no-highlight">647</i>&nbsp;     * Retrieves, but does not remove, the head (first element) of this list.
<i class="no-highlight">648</i>&nbsp;     *
<i class="no-highlight">649</i>&nbsp;     * @return the head of this list, or {@code null} if this list is empty
<i class="no-highlight">650</i>&nbsp;     * @since 1.5
<i class="no-highlight">651</i>&nbsp;     */
<i class="no-highlight">652</i>&nbsp;    public E peek() {
<b class="nc"><i class="no-highlight">653</i>&nbsp;        final Node&lt;E&gt; f = first;</b>
<b class="nc"><i class="no-highlight">654</i>&nbsp;        return (f == null) ? null : f.item;</b>
<i class="no-highlight">655</i>&nbsp;    }
<i class="no-highlight">656</i>&nbsp;
<i class="no-highlight">657</i>&nbsp;    /**
<i class="no-highlight">658</i>&nbsp;     * Retrieves, but does not remove, the head (first element) of this list.
<i class="no-highlight">659</i>&nbsp;     *
<i class="no-highlight">660</i>&nbsp;     * @return the head of this list
<i class="no-highlight">661</i>&nbsp;     * @throws NoSuchElementException if this list is empty
<i class="no-highlight">662</i>&nbsp;     * @since 1.5
<i class="no-highlight">663</i>&nbsp;     */
<i class="no-highlight">664</i>&nbsp;    public E element() {
<b class="nc"><i class="no-highlight">665</i>&nbsp;        return getFirst();</b>
<i class="no-highlight">666</i>&nbsp;    }
<i class="no-highlight">667</i>&nbsp;
<i class="no-highlight">668</i>&nbsp;    /**
<i class="no-highlight">669</i>&nbsp;     * Retrieves and removes the head (first element) of this list.
<i class="no-highlight">670</i>&nbsp;     *
<i class="no-highlight">671</i>&nbsp;     * @return the head of this list, or {@code null} if this list is empty
<i class="no-highlight">672</i>&nbsp;     * @since 1.5
<i class="no-highlight">673</i>&nbsp;     */
<i class="no-highlight">674</i>&nbsp;    public E poll() {
<b class="nc"><i class="no-highlight">675</i>&nbsp;        final Node&lt;E&gt; f = first;</b>
<b class="nc"><i class="no-highlight">676</i>&nbsp;        return (f == null) ? null : unlinkFirst(f);</b>
<i class="no-highlight">677</i>&nbsp;    }
<i class="no-highlight">678</i>&nbsp;
<i class="no-highlight">679</i>&nbsp;    /**
<i class="no-highlight">680</i>&nbsp;     * Retrieves and removes the head (first element) of this list.
<i class="no-highlight">681</i>&nbsp;     *
<i class="no-highlight">682</i>&nbsp;     * @return the head of this list
<i class="no-highlight">683</i>&nbsp;     * @throws NoSuchElementException if this list is empty
<i class="no-highlight">684</i>&nbsp;     * @since 1.5
<i class="no-highlight">685</i>&nbsp;     */
<i class="no-highlight">686</i>&nbsp;    public E remove() {
<b class="nc"><i class="no-highlight">687</i>&nbsp;        return removeFirst();</b>
<i class="no-highlight">688</i>&nbsp;    }
<i class="no-highlight">689</i>&nbsp;
<i class="no-highlight">690</i>&nbsp;    /**
<i class="no-highlight">691</i>&nbsp;     * Adds the specified element as the tail (last element) of this list.
<i class="no-highlight">692</i>&nbsp;     *
<i class="no-highlight">693</i>&nbsp;     * @param e the element to add
<i class="no-highlight">694</i>&nbsp;     * @return {@code true} (as specified by {@link Queue#offer})
<i class="no-highlight">695</i>&nbsp;     * @since 1.5
<i class="no-highlight">696</i>&nbsp;     */
<i class="no-highlight">697</i>&nbsp;    public boolean offer(E e) {
<b class="nc"><i class="no-highlight">698</i>&nbsp;        return add(e);</b>
<i class="no-highlight">699</i>&nbsp;    }
<i class="no-highlight">700</i>&nbsp;
<i class="no-highlight">701</i>&nbsp;    // Deque operations
<i class="no-highlight">702</i>&nbsp;    /**
<i class="no-highlight">703</i>&nbsp;     * Inserts the specified element at the front of this list.
<i class="no-highlight">704</i>&nbsp;     *
<i class="no-highlight">705</i>&nbsp;     * @param e the element to insert
<i class="no-highlight">706</i>&nbsp;     * @return {@code true} (as specified by {@link Deque#offerFirst})
<i class="no-highlight">707</i>&nbsp;     * @since 1.6
<i class="no-highlight">708</i>&nbsp;     */
<i class="no-highlight">709</i>&nbsp;    public boolean offerFirst(E e) {
<b class="nc"><i class="no-highlight">710</i>&nbsp;        addFirst(e);</b>
<b class="nc"><i class="no-highlight">711</i>&nbsp;        return true;</b>
<i class="no-highlight">712</i>&nbsp;    }
<i class="no-highlight">713</i>&nbsp;
<i class="no-highlight">714</i>&nbsp;    /**
<i class="no-highlight">715</i>&nbsp;     * Inserts the specified element at the end of this list.
<i class="no-highlight">716</i>&nbsp;     *
<i class="no-highlight">717</i>&nbsp;     * @param e the element to insert
<i class="no-highlight">718</i>&nbsp;     * @return {@code true} (as specified by {@link Deque#offerLast})
<i class="no-highlight">719</i>&nbsp;     * @since 1.6
<i class="no-highlight">720</i>&nbsp;     */
<i class="no-highlight">721</i>&nbsp;    public boolean offerLast(E e) {
<b class="nc"><i class="no-highlight">722</i>&nbsp;        addLast(e);</b>
<b class="nc"><i class="no-highlight">723</i>&nbsp;        return true;</b>
<i class="no-highlight">724</i>&nbsp;    }
<i class="no-highlight">725</i>&nbsp;
<i class="no-highlight">726</i>&nbsp;    /**
<i class="no-highlight">727</i>&nbsp;     * Retrieves, but does not remove, the first element of this list,
<i class="no-highlight">728</i>&nbsp;     * or returns {@code null} if this list is empty.
<i class="no-highlight">729</i>&nbsp;     *
<i class="no-highlight">730</i>&nbsp;     * @return the first element of this list, or {@code null}
<i class="no-highlight">731</i>&nbsp;     *         if this list is empty
<i class="no-highlight">732</i>&nbsp;     * @since 1.6
<i class="no-highlight">733</i>&nbsp;     */
<i class="no-highlight">734</i>&nbsp;    public E peekFirst() {
<b class="nc"><i class="no-highlight">735</i>&nbsp;        final Node&lt;E&gt; f = first;</b>
<b class="nc"><i class="no-highlight">736</i>&nbsp;        return (f == null) ? null : f.item;</b>
<i class="no-highlight">737</i>&nbsp;    }
<i class="no-highlight">738</i>&nbsp;
<i class="no-highlight">739</i>&nbsp;    /**
<i class="no-highlight">740</i>&nbsp;     * Retrieves, but does not remove, the last element of this list,
<i class="no-highlight">741</i>&nbsp;     * or returns {@code null} if this list is empty.
<i class="no-highlight">742</i>&nbsp;     *
<i class="no-highlight">743</i>&nbsp;     * @return the last element of this list, or {@code null}
<i class="no-highlight">744</i>&nbsp;     *         if this list is empty
<i class="no-highlight">745</i>&nbsp;     * @since 1.6
<i class="no-highlight">746</i>&nbsp;     */
<i class="no-highlight">747</i>&nbsp;    public E peekLast() {
<b class="nc"><i class="no-highlight">748</i>&nbsp;        final Node&lt;E&gt; l = last;</b>
<b class="nc"><i class="no-highlight">749</i>&nbsp;        return (l == null) ? null : l.item;</b>
<i class="no-highlight">750</i>&nbsp;    }
<i class="no-highlight">751</i>&nbsp;
<i class="no-highlight">752</i>&nbsp;    /**
<i class="no-highlight">753</i>&nbsp;     * Retrieves and removes the first element of this list,
<i class="no-highlight">754</i>&nbsp;     * or returns {@code null} if this list is empty.
<i class="no-highlight">755</i>&nbsp;     *
<i class="no-highlight">756</i>&nbsp;     * @return the first element of this list, or {@code null} if
<i class="no-highlight">757</i>&nbsp;     *     this list is empty
<i class="no-highlight">758</i>&nbsp;     * @since 1.6
<i class="no-highlight">759</i>&nbsp;     */
<i class="no-highlight">760</i>&nbsp;    public E pollFirst() {
<b class="nc"><i class="no-highlight">761</i>&nbsp;        final Node&lt;E&gt; f = first;</b>
<b class="nc"><i class="no-highlight">762</i>&nbsp;        return (f == null) ? null : unlinkFirst(f);</b>
<i class="no-highlight">763</i>&nbsp;    }
<i class="no-highlight">764</i>&nbsp;
<i class="no-highlight">765</i>&nbsp;    /**
<i class="no-highlight">766</i>&nbsp;     * Retrieves and removes the last element of this list,
<i class="no-highlight">767</i>&nbsp;     * or returns {@code null} if this list is empty.
<i class="no-highlight">768</i>&nbsp;     *
<i class="no-highlight">769</i>&nbsp;     * @return the last element of this list, or {@code null} if
<i class="no-highlight">770</i>&nbsp;     *     this list is empty
<i class="no-highlight">771</i>&nbsp;     * @since 1.6
<i class="no-highlight">772</i>&nbsp;     */
<i class="no-highlight">773</i>&nbsp;    public E pollLast() {
<b class="nc"><i class="no-highlight">774</i>&nbsp;        final Node&lt;E&gt; l = last;</b>
<b class="nc"><i class="no-highlight">775</i>&nbsp;        return (l == null) ? null : unlinkLast(l);</b>
<i class="no-highlight">776</i>&nbsp;    }
<i class="no-highlight">777</i>&nbsp;
<i class="no-highlight">778</i>&nbsp;    /**
<i class="no-highlight">779</i>&nbsp;     * Pushes an element onto the stack represented by this list.  In other
<i class="no-highlight">780</i>&nbsp;     * words, inserts the element at the front of this list.
<i class="no-highlight">781</i>&nbsp;     *
<i class="no-highlight">782</i>&nbsp;     * &lt;p&gt;This method is equivalent to {@link #addFirst}.
<i class="no-highlight">783</i>&nbsp;     *
<i class="no-highlight">784</i>&nbsp;     * @param e the element to push
<i class="no-highlight">785</i>&nbsp;     * @since 1.6
<i class="no-highlight">786</i>&nbsp;     */
<i class="no-highlight">787</i>&nbsp;    public void push(E e) {
<b class="nc"><i class="no-highlight">788</i>&nbsp;        addFirst(e);</b>
<b class="nc"><i class="no-highlight">789</i>&nbsp;    }</b>
<i class="no-highlight">790</i>&nbsp;
<i class="no-highlight">791</i>&nbsp;    /**
<i class="no-highlight">792</i>&nbsp;     * Pops an element from the stack represented by this list.  In other
<i class="no-highlight">793</i>&nbsp;     * words, removes and returns the first element of this list.
<i class="no-highlight">794</i>&nbsp;     *
<i class="no-highlight">795</i>&nbsp;     * &lt;p&gt;This method is equivalent to {@link #removeFirst()}.
<i class="no-highlight">796</i>&nbsp;     *
<i class="no-highlight">797</i>&nbsp;     * @return the element at the front of this list (which is the top
<i class="no-highlight">798</i>&nbsp;     *         of the stack represented by this list)
<i class="no-highlight">799</i>&nbsp;     * @throws NoSuchElementException if this list is empty
<i class="no-highlight">800</i>&nbsp;     * @since 1.6
<i class="no-highlight">801</i>&nbsp;     */
<i class="no-highlight">802</i>&nbsp;    public E pop() {
<b class="nc"><i class="no-highlight">803</i>&nbsp;        return removeFirst();</b>
<i class="no-highlight">804</i>&nbsp;    }
<i class="no-highlight">805</i>&nbsp;
<i class="no-highlight">806</i>&nbsp;    /**
<i class="no-highlight">807</i>&nbsp;     * Removes the first occurrence of the specified element in this
<i class="no-highlight">808</i>&nbsp;     * list (when traversing the list from head to tail).  If the list
<i class="no-highlight">809</i>&nbsp;     * does not contain the element, it is unchanged.
<i class="no-highlight">810</i>&nbsp;     *
<i class="no-highlight">811</i>&nbsp;     * @param o element to be removed from this list, if present
<i class="no-highlight">812</i>&nbsp;     * @return {@code true} if the list contained the specified element
<i class="no-highlight">813</i>&nbsp;     * @since 1.6
<i class="no-highlight">814</i>&nbsp;     */
<i class="no-highlight">815</i>&nbsp;    public boolean removeFirstOccurrence(Object o) {
<b class="nc"><i class="no-highlight">816</i>&nbsp;        return remove(o);</b>
<i class="no-highlight">817</i>&nbsp;    }
<i class="no-highlight">818</i>&nbsp;
<i class="no-highlight">819</i>&nbsp;    /**
<i class="no-highlight">820</i>&nbsp;     * Removes the last occurrence of the specified element in this
<i class="no-highlight">821</i>&nbsp;     * list (when traversing the list from head to tail).  If the list
<i class="no-highlight">822</i>&nbsp;     * does not contain the element, it is unchanged.
<i class="no-highlight">823</i>&nbsp;     *
<i class="no-highlight">824</i>&nbsp;     * @param o element to be removed from this list, if present
<i class="no-highlight">825</i>&nbsp;     * @return {@code true} if the list contained the specified element
<i class="no-highlight">826</i>&nbsp;     * @since 1.6
<i class="no-highlight">827</i>&nbsp;     */
<i class="no-highlight">828</i>&nbsp;    public boolean removeLastOccurrence(Object o) {
<b class="nc"><i class="no-highlight">829</i>&nbsp;        if (o == null) {</b>
<b class="nc"><i class="no-highlight">830</i>&nbsp;            for (Node&lt;E&gt; x = last; x != null; x = x.prev) {</b>
<b class="nc"><i class="no-highlight">831</i>&nbsp;                if (x.item == null) {</b>
<b class="nc"><i class="no-highlight">832</i>&nbsp;                    unlink(x);</b>
<b class="nc"><i class="no-highlight">833</i>&nbsp;                    return true;</b>
<i class="no-highlight">834</i>&nbsp;                }
<i class="no-highlight">835</i>&nbsp;            }
<i class="no-highlight">836</i>&nbsp;        } else {
<b class="nc"><i class="no-highlight">837</i>&nbsp;            for (Node&lt;E&gt; x = last; x != null; x = x.prev) {</b>
<b class="nc"><i class="no-highlight">838</i>&nbsp;                if (o.equals(x.item)) {</b>
<b class="nc"><i class="no-highlight">839</i>&nbsp;                    unlink(x);</b>
<b class="nc"><i class="no-highlight">840</i>&nbsp;                    return true;</b>
<i class="no-highlight">841</i>&nbsp;                }
<i class="no-highlight">842</i>&nbsp;            }
<i class="no-highlight">843</i>&nbsp;        }
<b class="nc"><i class="no-highlight">844</i>&nbsp;        return false;</b>
<i class="no-highlight">845</i>&nbsp;    }
<i class="no-highlight">846</i>&nbsp;
<i class="no-highlight">847</i>&nbsp;    /**
<i class="no-highlight">848</i>&nbsp;     * Returns a list-iterator of the elements in this list (in proper
<i class="no-highlight">849</i>&nbsp;     * sequence), starting at the specified position in the list.
<i class="no-highlight">850</i>&nbsp;     * Obeys the general contract of {@code List.listIterator(int)}.&lt;p&gt;
<i class="no-highlight">851</i>&nbsp;     *
<i class="no-highlight">852</i>&nbsp;     * The list-iterator is &lt;i&gt;fail-fast&lt;/i&gt;: if the list is structurally
<i class="no-highlight">853</i>&nbsp;     * modified at any time after the Iterator is created, in any way except
<i class="no-highlight">854</i>&nbsp;     * through the list-iterator&#39;s own {@code remove} or {@code add}
<i class="no-highlight">855</i>&nbsp;     * methods, the list-iterator will throw a
<i class="no-highlight">856</i>&nbsp;     * {@code ConcurrentModificationException}.  Thus, in the face of
<i class="no-highlight">857</i>&nbsp;     * concurrent modification, the iterator fails quickly and cleanly, rather
<i class="no-highlight">858</i>&nbsp;     * than risking arbitrary, non-deterministic behavior at an undetermined
<i class="no-highlight">859</i>&nbsp;     * time in the future.
<i class="no-highlight">860</i>&nbsp;     *
<i class="no-highlight">861</i>&nbsp;     * @param index index of the first element to be returned from the
<i class="no-highlight">862</i>&nbsp;     *              list-iterator (by a call to {@code next})
<i class="no-highlight">863</i>&nbsp;     * @return a ListIterator of the elements in this list (in proper
<i class="no-highlight">864</i>&nbsp;     *         sequence), starting at the specified position in the list
<i class="no-highlight">865</i>&nbsp;     * @throws IndexOutOfBoundsException {@inheritDoc}
<i class="no-highlight">866</i>&nbsp;     * @see List#listIterator(int)
<i class="no-highlight">867</i>&nbsp;     */
<i class="no-highlight">868</i>&nbsp;    public ListIterator&lt;E&gt; listIterator(int index) {
<b class="nc"><i class="no-highlight">869</i>&nbsp;        checkPositionIndex(index);</b>
<b class="nc"><i class="no-highlight">870</i>&nbsp;        return new ListItr(index);</b>
<i class="no-highlight">871</i>&nbsp;    }
<i class="no-highlight">872</i>&nbsp;
<i class="no-highlight">873</i>&nbsp;    private class ListItr implements ListIterator&lt;E&gt; {
<b class="nc"><i class="no-highlight">874</i>&nbsp;        private Node&lt;E&gt; lastReturned = null;</b>
<i class="no-highlight">875</i>&nbsp;        private Node&lt;E&gt; next;
<i class="no-highlight">876</i>&nbsp;        private int nextIndex;
<b class="nc"><i class="no-highlight">877</i>&nbsp;        private int expectedModCount = modCount;</b>
<i class="no-highlight">878</i>&nbsp;
<b class="nc"><i class="no-highlight">879</i>&nbsp;        ListItr(int index) {</b>
<i class="no-highlight">880</i>&nbsp;            // assert isPositionIndex(index);
<b class="nc"><i class="no-highlight">881</i>&nbsp;            next = (index == size) ? null : node(index);</b>
<b class="nc"><i class="no-highlight">882</i>&nbsp;            nextIndex = index;</b>
<i class="no-highlight">883</i>&nbsp;        }
<i class="no-highlight">884</i>&nbsp;
<i class="no-highlight">885</i>&nbsp;        public boolean hasNext() {
<b class="nc"><i class="no-highlight">886</i>&nbsp;            return nextIndex &lt; size;</b>
<i class="no-highlight">887</i>&nbsp;        }
<i class="no-highlight">888</i>&nbsp;
<i class="no-highlight">889</i>&nbsp;        public E next() {
<b class="nc"><i class="no-highlight">890</i>&nbsp;            checkForComodification();</b>
<b class="nc"><i class="no-highlight">891</i>&nbsp;            if (!hasNext())</b>
<b class="nc"><i class="no-highlight">892</i>&nbsp;                throw new NoSuchElementException();</b>
<i class="no-highlight">893</i>&nbsp;
<b class="nc"><i class="no-highlight">894</i>&nbsp;            lastReturned = next;</b>
<b class="nc"><i class="no-highlight">895</i>&nbsp;            next = next.next;</b>
<b class="nc"><i class="no-highlight">896</i>&nbsp;            nextIndex++;</b>
<b class="nc"><i class="no-highlight">897</i>&nbsp;            return lastReturned.item;</b>
<i class="no-highlight">898</i>&nbsp;        }
<i class="no-highlight">899</i>&nbsp;
<i class="no-highlight">900</i>&nbsp;        public boolean hasPrevious() {
<b class="nc"><i class="no-highlight">901</i>&nbsp;            return nextIndex &gt; 0;</b>
<i class="no-highlight">902</i>&nbsp;        }
<i class="no-highlight">903</i>&nbsp;
<i class="no-highlight">904</i>&nbsp;        public E previous() {
<b class="nc"><i class="no-highlight">905</i>&nbsp;            checkForComodification();</b>
<b class="nc"><i class="no-highlight">906</i>&nbsp;            if (!hasPrevious())</b>
<b class="nc"><i class="no-highlight">907</i>&nbsp;                throw new NoSuchElementException();</b>
<i class="no-highlight">908</i>&nbsp;
<b class="nc"><i class="no-highlight">909</i>&nbsp;            lastReturned = next = (next == null) ? last : next.prev;</b>
<b class="nc"><i class="no-highlight">910</i>&nbsp;            nextIndex--;</b>
<b class="nc"><i class="no-highlight">911</i>&nbsp;            return lastReturned.item;</b>
<i class="no-highlight">912</i>&nbsp;        }
<i class="no-highlight">913</i>&nbsp;
<i class="no-highlight">914</i>&nbsp;        public int nextIndex() {
<b class="nc"><i class="no-highlight">915</i>&nbsp;            return nextIndex;</b>
<i class="no-highlight">916</i>&nbsp;        }
<i class="no-highlight">917</i>&nbsp;
<i class="no-highlight">918</i>&nbsp;        public int previousIndex() {
<b class="nc"><i class="no-highlight">919</i>&nbsp;            return nextIndex - 1;</b>
<i class="no-highlight">920</i>&nbsp;        }
<i class="no-highlight">921</i>&nbsp;
<i class="no-highlight">922</i>&nbsp;        public void remove() {
<b class="nc"><i class="no-highlight">923</i>&nbsp;            checkForComodification();</b>
<b class="nc"><i class="no-highlight">924</i>&nbsp;            if (lastReturned == null)</b>
<b class="nc"><i class="no-highlight">925</i>&nbsp;                throw new IllegalStateException();</b>
<i class="no-highlight">926</i>&nbsp;
<b class="nc"><i class="no-highlight">927</i>&nbsp;            Node&lt;E&gt; lastNext = lastReturned.next;</b>
<b class="nc"><i class="no-highlight">928</i>&nbsp;            unlink(lastReturned);</b>
<b class="nc"><i class="no-highlight">929</i>&nbsp;            if (next == lastReturned)</b>
<b class="nc"><i class="no-highlight">930</i>&nbsp;                next = lastNext;</b>
<i class="no-highlight">931</i>&nbsp;            else
<b class="nc"><i class="no-highlight">932</i>&nbsp;                nextIndex--;</b>
<b class="nc"><i class="no-highlight">933</i>&nbsp;            lastReturned = null;</b>
<b class="nc"><i class="no-highlight">934</i>&nbsp;            expectedModCount++;</b>
<i class="no-highlight">935</i>&nbsp;        }
<i class="no-highlight">936</i>&nbsp;
<i class="no-highlight">937</i>&nbsp;        public void set(E e) {
<b class="nc"><i class="no-highlight">938</i>&nbsp;            if (lastReturned == null)</b>
<b class="nc"><i class="no-highlight">939</i>&nbsp;                throw new IllegalStateException();</b>
<b class="nc"><i class="no-highlight">940</i>&nbsp;            checkForComodification();</b>
<b class="nc"><i class="no-highlight">941</i>&nbsp;            lastReturned.item = e;</b>
<i class="no-highlight">942</i>&nbsp;        }
<i class="no-highlight">943</i>&nbsp;
<i class="no-highlight">944</i>&nbsp;        public void add(E e) {
<b class="nc"><i class="no-highlight">945</i>&nbsp;            checkForComodification();</b>
<b class="nc"><i class="no-highlight">946</i>&nbsp;            lastReturned = null;</b>
<b class="nc"><i class="no-highlight">947</i>&nbsp;            if (next == null)</b>
<b class="nc"><i class="no-highlight">948</i>&nbsp;                linkLast(e);</b>
<i class="no-highlight">949</i>&nbsp;            else
<b class="nc"><i class="no-highlight">950</i>&nbsp;                linkBefore(e, next);</b>
<b class="nc"><i class="no-highlight">951</i>&nbsp;            nextIndex++;</b>
<b class="nc"><i class="no-highlight">952</i>&nbsp;            expectedModCount++;</b>
<i class="no-highlight">953</i>&nbsp;        }
<i class="no-highlight">954</i>&nbsp;
<i class="no-highlight">955</i>&nbsp;        public void forEachRemaining(Consumer&lt;? super E&gt; action) {
<b class="nc"><i class="no-highlight">956</i>&nbsp;            Objects.requireNonNull(action);</b>
<b class="nc"><i class="no-highlight">957</i>&nbsp;            while (modCount == expectedModCount &amp;&amp; nextIndex &lt; size) {</b>
<b class="nc"><i class="no-highlight">958</i>&nbsp;                action.accept(next.item);</b>
<b class="nc"><i class="no-highlight">959</i>&nbsp;                lastReturned = next;</b>
<b class="nc"><i class="no-highlight">960</i>&nbsp;                next = next.next;</b>
<b class="nc"><i class="no-highlight">961</i>&nbsp;                nextIndex++;</b>
<i class="no-highlight">962</i>&nbsp;            }
<b class="nc"><i class="no-highlight">963</i>&nbsp;            checkForComodification();</b>
<i class="no-highlight">964</i>&nbsp;        }
<i class="no-highlight">965</i>&nbsp;
<i class="no-highlight">966</i>&nbsp;        final void checkForComodification() {
<b class="nc"><i class="no-highlight">967</i>&nbsp;            if (modCount != expectedModCount)</b>
<b class="nc"><i class="no-highlight">968</i>&nbsp;                throw new ConcurrentModificationException();</b>
<i class="no-highlight">969</i>&nbsp;        }
<i class="no-highlight">970</i>&nbsp;    }
<i class="no-highlight">971</i>&nbsp;
<i class="no-highlight">972</i>&nbsp;    private static class Node&lt;E&gt; {
<i class="no-highlight">973</i>&nbsp;        E item;
<i class="no-highlight">974</i>&nbsp;        Node&lt;E&gt; next;
<i class="no-highlight">975</i>&nbsp;        Node&lt;E&gt; prev;
<i class="no-highlight">976</i>&nbsp;
<b class="fc"><i class="no-highlight">977</i>&nbsp;        Node(Node&lt;E&gt; prev, E element, Node&lt;E&gt; next) {</b>
<b class="fc"><i class="no-highlight">978</i>&nbsp;            this.item = element;</b>
<b class="fc"><i class="no-highlight">979</i>&nbsp;            this.next = next;</b>
<b class="fc"><i class="no-highlight">980</i>&nbsp;            this.prev = prev;</b>
<b class="fc"><i class="no-highlight">981</i>&nbsp;        }</b>
<i class="no-highlight">982</i>&nbsp;    }
<i class="no-highlight">983</i>&nbsp;
<i class="no-highlight">984</i>&nbsp;    /**
<i class="no-highlight">985</i>&nbsp;     * @since 1.6
<i class="no-highlight">986</i>&nbsp;     */
<i class="no-highlight">987</i>&nbsp;    public Iterator&lt;E&gt; descendingIterator() {
<b class="nc"><i class="no-highlight">988</i>&nbsp;        return new DescendingIterator();</b>
<i class="no-highlight">989</i>&nbsp;    }
<i class="no-highlight">990</i>&nbsp;
<i class="no-highlight">991</i>&nbsp;    /**
<i class="no-highlight">992</i>&nbsp;     * Adapter to provide descending iterators via ListItr.previous
<i class="no-highlight">993</i>&nbsp;     */
<b class="nc"><i class="no-highlight">994</i>&nbsp;    private class DescendingIterator implements Iterator&lt;E&gt; {</b>
<b class="nc"><i class="no-highlight">995</i>&nbsp;        private final ListItr itr = new ListItr(size());</b>
<i class="no-highlight">996</i>&nbsp;        public boolean hasNext() {
<b class="nc"><i class="no-highlight">997</i>&nbsp;            return itr.hasPrevious();</b>
<i class="no-highlight">998</i>&nbsp;        }
<i class="no-highlight">999</i>&nbsp;        public E next() {
<b class="nc"><i class="no-highlight">1000</i>&nbsp;            return itr.previous();</b>
<i class="no-highlight">1001</i>&nbsp;        }
<i class="no-highlight">1002</i>&nbsp;        public void remove() {
<b class="nc"><i class="no-highlight">1003</i>&nbsp;            itr.remove();</b>
<i class="no-highlight">1004</i>&nbsp;        }
<i class="no-highlight">1005</i>&nbsp;    }
<i class="no-highlight">1006</i>&nbsp;
<i class="no-highlight">1007</i>&nbsp;    @SuppressWarnings(&quot;unchecked&quot;)
<i class="no-highlight">1008</i>&nbsp;    private LinkedList&lt;E&gt; superClone() {
<i class="no-highlight">1009</i>&nbsp;        try {
<b class="nc"><i class="no-highlight">1010</i>&nbsp;            return (LinkedList&lt;E&gt;) super.clone();</b>
<b class="nc"><i class="no-highlight">1011</i>&nbsp;        } catch (CloneNotSupportedException e) {</b>
<b class="nc"><i class="no-highlight">1012</i>&nbsp;            throw new InternalError(e);</b>
<i class="no-highlight">1013</i>&nbsp;        }
<i class="no-highlight">1014</i>&nbsp;    }
<i class="no-highlight">1015</i>&nbsp;
<i class="no-highlight">1016</i>&nbsp;    /**
<i class="no-highlight">1017</i>&nbsp;     * Returns a shallow copy of this {@code LinkedList}. (The elements
<i class="no-highlight">1018</i>&nbsp;     * themselves are not cloned.)
<i class="no-highlight">1019</i>&nbsp;     *
<i class="no-highlight">1020</i>&nbsp;     * @return a shallow copy of this {@code LinkedList} instance
<i class="no-highlight">1021</i>&nbsp;     */
<i class="no-highlight">1022</i>&nbsp;    public Object clone() {
<b class="nc"><i class="no-highlight">1023</i>&nbsp;        LinkedList&lt;E&gt; clone = superClone();</b>
<i class="no-highlight">1024</i>&nbsp;
<i class="no-highlight">1025</i>&nbsp;        // Put clone into &quot;virgin&quot; state
<b class="nc"><i class="no-highlight">1026</i>&nbsp;        clone.first = clone.last = null;</b>
<b class="nc"><i class="no-highlight">1027</i>&nbsp;        clone.size = 0;</b>
<b class="nc"><i class="no-highlight">1028</i>&nbsp;        clone.modCount = 0;</b>
<i class="no-highlight">1029</i>&nbsp;
<i class="no-highlight">1030</i>&nbsp;        // Initialize clone with our elements
<b class="nc"><i class="no-highlight">1031</i>&nbsp;        for (Node&lt;E&gt; x = first; x != null; x = x.next)</b>
<b class="nc"><i class="no-highlight">1032</i>&nbsp;            clone.add(x.item);</b>
<i class="no-highlight">1033</i>&nbsp;
<b class="nc"><i class="no-highlight">1034</i>&nbsp;        return clone;</b>
<i class="no-highlight">1035</i>&nbsp;    }
<i class="no-highlight">1036</i>&nbsp;
<i class="no-highlight">1037</i>&nbsp;    /**
<i class="no-highlight">1038</i>&nbsp;     * Returns an array containing all of the elements in this list
<i class="no-highlight">1039</i>&nbsp;     * in proper sequence (from first to last element).
<i class="no-highlight">1040</i>&nbsp;     *
<i class="no-highlight">1041</i>&nbsp;     * &lt;p&gt;The returned array will be &quot;safe&quot; in that no references to it are
<i class="no-highlight">1042</i>&nbsp;     * maintained by this list.  (In other words, this method must allocate
<i class="no-highlight">1043</i>&nbsp;     * a new array).  The caller is thus free to modify the returned array.
<i class="no-highlight">1044</i>&nbsp;     *
<i class="no-highlight">1045</i>&nbsp;     * &lt;p&gt;This method acts as bridge between array-based and collection-based
<i class="no-highlight">1046</i>&nbsp;     * APIs.
<i class="no-highlight">1047</i>&nbsp;     *
<i class="no-highlight">1048</i>&nbsp;     * @return an array containing all of the elements in this list
<i class="no-highlight">1049</i>&nbsp;     *         in proper sequence
<i class="no-highlight">1050</i>&nbsp;     */
<i class="no-highlight">1051</i>&nbsp;    public Object[] toArray() {
<b class="nc"><i class="no-highlight">1052</i>&nbsp;        Object[] result = new Object[size];</b>
<b class="nc"><i class="no-highlight">1053</i>&nbsp;        int i = 0;</b>
<b class="nc"><i class="no-highlight">1054</i>&nbsp;        for (Node&lt;E&gt; x = first; x != null; x = x.next)</b>
<b class="nc"><i class="no-highlight">1055</i>&nbsp;            result[i++] = x.item;</b>
<b class="nc"><i class="no-highlight">1056</i>&nbsp;        return result;</b>
<i class="no-highlight">1057</i>&nbsp;    }
<i class="no-highlight">1058</i>&nbsp;
<i class="no-highlight">1059</i>&nbsp;    /**
<i class="no-highlight">1060</i>&nbsp;     * Returns an array containing all of the elements in this list in
<i class="no-highlight">1061</i>&nbsp;     * proper sequence (from first to last element); the runtime type of
<i class="no-highlight">1062</i>&nbsp;     * the returned array is that of the specified array.  If the list fits
<i class="no-highlight">1063</i>&nbsp;     * in the specified array, it is returned therein.  Otherwise, a new
<i class="no-highlight">1064</i>&nbsp;     * array is allocated with the runtime type of the specified array and
<i class="no-highlight">1065</i>&nbsp;     * the size of this list.
<i class="no-highlight">1066</i>&nbsp;     *
<i class="no-highlight">1067</i>&nbsp;     * &lt;p&gt;If the list fits in the specified array with room to spare (i.e.,
<i class="no-highlight">1068</i>&nbsp;     * the array has more elements than the list), the element in the array
<i class="no-highlight">1069</i>&nbsp;     * immediately following the end of the list is set to {@code null}.
<i class="no-highlight">1070</i>&nbsp;     * (This is useful in determining the length of the list &lt;i&gt;only&lt;/i&gt; if
<i class="no-highlight">1071</i>&nbsp;     * the caller knows that the list does not contain any null elements.)
<i class="no-highlight">1072</i>&nbsp;     *
<i class="no-highlight">1073</i>&nbsp;     * &lt;p&gt;Like the {@link #toArray()} method, this method acts as bridge between
<i class="no-highlight">1074</i>&nbsp;     * array-based and collection-based APIs.  Further, this method allows
<i class="no-highlight">1075</i>&nbsp;     * precise control over the runtime type of the output array, and may,
<i class="no-highlight">1076</i>&nbsp;     * under certain circumstances, be used to save allocation costs.
<i class="no-highlight">1077</i>&nbsp;     *
<i class="no-highlight">1078</i>&nbsp;     * &lt;p&gt;Suppose {@code x} is a list known to contain only strings.
<i class="no-highlight">1079</i>&nbsp;     * The following code can be used to dump the list into a newly
<i class="no-highlight">1080</i>&nbsp;     * allocated array of {@code String}:
<i class="no-highlight">1081</i>&nbsp;     *
<i class="no-highlight">1082</i>&nbsp;     * &lt;pre&gt;
<i class="no-highlight">1083</i>&nbsp;     *     String[] y = x.toArray(new String[0]);&lt;/pre&gt;
<i class="no-highlight">1084</i>&nbsp;     *
<i class="no-highlight">1085</i>&nbsp;     * Note that {@code toArray(new Object[0])} is identical in function to
<i class="no-highlight">1086</i>&nbsp;     * {@code toArray()}.
<i class="no-highlight">1087</i>&nbsp;     *
<i class="no-highlight">1088</i>&nbsp;     * @param a the array into which the elements of the list are to
<i class="no-highlight">1089</i>&nbsp;     *          be stored, if it is big enough; otherwise, a new array of the
<i class="no-highlight">1090</i>&nbsp;     *          same runtime type is allocated for this purpose.
<i class="no-highlight">1091</i>&nbsp;     * @return an array containing the elements of the list
<i class="no-highlight">1092</i>&nbsp;     * @throws ArrayStoreException if the runtime type of the specified array
<i class="no-highlight">1093</i>&nbsp;     *         is not a supertype of the runtime type of every element in
<i class="no-highlight">1094</i>&nbsp;     *         this list
<i class="no-highlight">1095</i>&nbsp;     * @throws NullPointerException if the specified array is null
<i class="no-highlight">1096</i>&nbsp;     */
<i class="no-highlight">1097</i>&nbsp;    @SuppressWarnings(&quot;unchecked&quot;)
<i class="no-highlight">1098</i>&nbsp;    public &lt;T&gt; T[] toArray(T[] a) {
<b class="nc"><i class="no-highlight">1099</i>&nbsp;        if (a.length &lt; size)</b>
<b class="nc"><i class="no-highlight">1100</i>&nbsp;            a = (T[])java.lang.reflect.Array.newInstance(</b>
<b class="nc"><i class="no-highlight">1101</i>&nbsp;                    a.getClass().getComponentType(), size);</b>
<b class="nc"><i class="no-highlight">1102</i>&nbsp;        int i = 0;</b>
<b class="nc"><i class="no-highlight">1103</i>&nbsp;        Object[] result = a;</b>
<b class="nc"><i class="no-highlight">1104</i>&nbsp;        for (Node&lt;E&gt; x = first; x != null; x = x.next)</b>
<b class="nc"><i class="no-highlight">1105</i>&nbsp;            result[i++] = x.item;</b>
<i class="no-highlight">1106</i>&nbsp;
<b class="nc"><i class="no-highlight">1107</i>&nbsp;        if (a.length &gt; size)</b>
<b class="nc"><i class="no-highlight">1108</i>&nbsp;            a[size] = null;</b>
<i class="no-highlight">1109</i>&nbsp;
<b class="nc"><i class="no-highlight">1110</i>&nbsp;        return a;</b>
<i class="no-highlight">1111</i>&nbsp;    }
<i class="no-highlight">1112</i>&nbsp;
<i class="no-highlight">1113</i>&nbsp;    private static final long serialVersionUID = 876323262645176354L;
<i class="no-highlight">1114</i>&nbsp;
<i class="no-highlight">1115</i>&nbsp;    /**
<i class="no-highlight">1116</i>&nbsp;     * Saves the state of this {@code LinkedList} instance to a stream
<i class="no-highlight">1117</i>&nbsp;     * (that is, serializes it).
<i class="no-highlight">1118</i>&nbsp;     *
<i class="no-highlight">1119</i>&nbsp;     * @serialData The size of the list (the number of elements it
<i class="no-highlight">1120</i>&nbsp;     *             contains) is emitted (int), followed by all of its
<i class="no-highlight">1121</i>&nbsp;     *             elements (each an Object) in the proper order.
<i class="no-highlight">1122</i>&nbsp;     */
<i class="no-highlight">1123</i>&nbsp;    private void writeObject(java.io.ObjectOutputStream s)
<i class="no-highlight">1124</i>&nbsp;            throws java.io.IOException {
<i class="no-highlight">1125</i>&nbsp;        // Write out any hidden serialization magic
<b class="nc"><i class="no-highlight">1126</i>&nbsp;        s.defaultWriteObject();</b>
<i class="no-highlight">1127</i>&nbsp;
<i class="no-highlight">1128</i>&nbsp;        // Write out size
<b class="nc"><i class="no-highlight">1129</i>&nbsp;        s.writeInt(size);</b>
<i class="no-highlight">1130</i>&nbsp;
<i class="no-highlight">1131</i>&nbsp;        // Write out all elements in the proper order.
<b class="nc"><i class="no-highlight">1132</i>&nbsp;        for (Node&lt;E&gt; x = first; x != null; x = x.next)</b>
<b class="nc"><i class="no-highlight">1133</i>&nbsp;            s.writeObject(x.item);</b>
<b class="nc"><i class="no-highlight">1134</i>&nbsp;    }</b>
<i class="no-highlight">1135</i>&nbsp;
<i class="no-highlight">1136</i>&nbsp;    /**
<i class="no-highlight">1137</i>&nbsp;     * Reconstitutes this {@code LinkedList} instance from a stream
<i class="no-highlight">1138</i>&nbsp;     * (that is, deserializes it).
<i class="no-highlight">1139</i>&nbsp;     */
<i class="no-highlight">1140</i>&nbsp;    @SuppressWarnings(&quot;unchecked&quot;)
<i class="no-highlight">1141</i>&nbsp;    private void readObject(java.io.ObjectInputStream s)
<i class="no-highlight">1142</i>&nbsp;            throws java.io.IOException, ClassNotFoundException {
<i class="no-highlight">1143</i>&nbsp;        // Read in any hidden serialization magic
<b class="nc"><i class="no-highlight">1144</i>&nbsp;        s.defaultReadObject();</b>
<i class="no-highlight">1145</i>&nbsp;
<i class="no-highlight">1146</i>&nbsp;        // Read in size
<b class="nc"><i class="no-highlight">1147</i>&nbsp;        int size = s.readInt();</b>
<i class="no-highlight">1148</i>&nbsp;
<i class="no-highlight">1149</i>&nbsp;        // Read in all elements in the proper order.
<b class="nc"><i class="no-highlight">1150</i>&nbsp;        for (int i = 0; i &lt; size; i++)</b>
<b class="nc"><i class="no-highlight">1151</i>&nbsp;            linkLast((E)s.readObject());</b>
<b class="nc"><i class="no-highlight">1152</i>&nbsp;    }</b>
<i class="no-highlight">1153</i>&nbsp;
<i class="no-highlight">1154</i>&nbsp;    /**
<i class="no-highlight">1155</i>&nbsp;     * Creates a &lt;em&gt;&lt;a href=&quot;Spliterator.html#binding&quot;&gt;late-binding&lt;/a&gt;&lt;/em&gt;
<i class="no-highlight">1156</i>&nbsp;     * and &lt;em&gt;fail-fast&lt;/em&gt; {@link Spliterator} over the elements in this
<i class="no-highlight">1157</i>&nbsp;     * list.
<i class="no-highlight">1158</i>&nbsp;     *
<i class="no-highlight">1159</i>&nbsp;     * &lt;p&gt;The {@code Spliterator} reports {@link Spliterator#SIZED} and
<i class="no-highlight">1160</i>&nbsp;     * {@link Spliterator#ORDERED}.  Overriding implementations should document
<i class="no-highlight">1161</i>&nbsp;     * the reporting of additional characteristic values.
<i class="no-highlight">1162</i>&nbsp;     *
<i class="no-highlight">1163</i>&nbsp;     * @implNote
<i class="no-highlight">1164</i>&nbsp;     * The {@code Spliterator} additionally reports {@link Spliterator#SUBSIZED}
<i class="no-highlight">1165</i>&nbsp;     * and implements {@code trySplit} to permit limited parallelism..
<i class="no-highlight">1166</i>&nbsp;     *
<i class="no-highlight">1167</i>&nbsp;     * @return a {@code Spliterator} over the elements in this list
<i class="no-highlight">1168</i>&nbsp;     * @since 1.8
<i class="no-highlight">1169</i>&nbsp;     */
<i class="no-highlight">1170</i>&nbsp;    @Override
<i class="no-highlight">1171</i>&nbsp;    public Spliterator&lt;E&gt; spliterator() {
<b class="nc"><i class="no-highlight">1172</i>&nbsp;        return new LLSpliterator&lt;E&gt;(this, -1, 0);</b>
<i class="no-highlight">1173</i>&nbsp;    }
<i class="no-highlight">1174</i>&nbsp;
<i class="no-highlight">1175</i>&nbsp;    /** A customized variant of Spliterators.IteratorSpliterator */
<i class="no-highlight">1176</i>&nbsp;    static final class LLSpliterator&lt;E&gt; implements Spliterator&lt;E&gt; {
<i class="no-highlight">1177</i>&nbsp;        static final int BATCH_UNIT = 1 &lt;&lt; 10;  // batch array size increment
<i class="no-highlight">1178</i>&nbsp;        static final int MAX_BATCH = 1 &lt;&lt; 25;  // max batch array size;
<i class="no-highlight">1179</i>&nbsp;        final LinkedList&lt;E&gt; list; // null OK unless traversed
<i class="no-highlight">1180</i>&nbsp;        Node&lt;E&gt; current;      // current node; null until initialized
<i class="no-highlight">1181</i>&nbsp;        int est;              // size estimate; -1 until first needed
<i class="no-highlight">1182</i>&nbsp;        int expectedModCount; // initialized when est set
<i class="no-highlight">1183</i>&nbsp;        int batch;            // batch size for splits
<i class="no-highlight">1184</i>&nbsp;
<b class="nc"><i class="no-highlight">1185</i>&nbsp;        LLSpliterator(LinkedList&lt;E&gt; list, int est, int expectedModCount) {</b>
<b class="nc"><i class="no-highlight">1186</i>&nbsp;            this.list = list;</b>
<b class="nc"><i class="no-highlight">1187</i>&nbsp;            this.est = est;</b>
<b class="nc"><i class="no-highlight">1188</i>&nbsp;            this.expectedModCount = expectedModCount;</b>
<i class="no-highlight">1189</i>&nbsp;        }
<i class="no-highlight">1190</i>&nbsp;
<i class="no-highlight">1191</i>&nbsp;        final int getEst() {
<i class="no-highlight">1192</i>&nbsp;            int s; // force initialization
<i class="no-highlight">1193</i>&nbsp;            final LinkedList&lt;E&gt; lst;
<b class="nc"><i class="no-highlight">1194</i>&nbsp;            if ((s = est) &lt; 0) {</b>
<b class="nc"><i class="no-highlight">1195</i>&nbsp;                if ((lst = list) == null)</b>
<b class="nc"><i class="no-highlight">1196</i>&nbsp;                    s = est = 0;</b>
<i class="no-highlight">1197</i>&nbsp;                else {
<b class="nc"><i class="no-highlight">1198</i>&nbsp;                    expectedModCount = lst.modCount;</b>
<b class="nc"><i class="no-highlight">1199</i>&nbsp;                    current = lst.first;</b>
<b class="nc"><i class="no-highlight">1200</i>&nbsp;                    s = est = lst.size;</b>
<i class="no-highlight">1201</i>&nbsp;                }
<i class="no-highlight">1202</i>&nbsp;            }
<b class="nc"><i class="no-highlight">1203</i>&nbsp;            return s;</b>
<i class="no-highlight">1204</i>&nbsp;        }
<i class="no-highlight">1205</i>&nbsp;
<b class="nc"><i class="no-highlight">1206</i>&nbsp;        public long estimateSize() { return (long) getEst(); }</b>
<i class="no-highlight">1207</i>&nbsp;
<i class="no-highlight">1208</i>&nbsp;        public Spliterator&lt;E&gt; trySplit() {
<i class="no-highlight">1209</i>&nbsp;            Node&lt;E&gt; p;
<b class="nc"><i class="no-highlight">1210</i>&nbsp;            int s = getEst();</b>
<b class="nc"><i class="no-highlight">1211</i>&nbsp;            if (s &gt; 1 &amp;&amp; (p = current) != null) {</b>
<b class="nc"><i class="no-highlight">1212</i>&nbsp;                int n = batch + BATCH_UNIT;</b>
<b class="nc"><i class="no-highlight">1213</i>&nbsp;                if (n &gt; s)</b>
<b class="nc"><i class="no-highlight">1214</i>&nbsp;                    n = s;</b>
<b class="nc"><i class="no-highlight">1215</i>&nbsp;                if (n &gt; MAX_BATCH)</b>
<b class="nc"><i class="no-highlight">1216</i>&nbsp;                    n = MAX_BATCH;</b>
<b class="nc"><i class="no-highlight">1217</i>&nbsp;                Object[] a = new Object[n];</b>
<b class="nc"><i class="no-highlight">1218</i>&nbsp;                int j = 0;</b>
<b class="nc"><i class="no-highlight">1219</i>&nbsp;                do { a[j++] = p.item; } while ((p = p.next) != null &amp;&amp; j &lt; n);</b>
<b class="nc"><i class="no-highlight">1220</i>&nbsp;                current = p;</b>
<b class="nc"><i class="no-highlight">1221</i>&nbsp;                batch = j;</b>
<b class="nc"><i class="no-highlight">1222</i>&nbsp;                est = s - j;</b>
<b class="nc"><i class="no-highlight">1223</i>&nbsp;                return Spliterators.spliterator(a, 0, j, Spliterator.ORDERED);</b>
<i class="no-highlight">1224</i>&nbsp;            }
<b class="nc"><i class="no-highlight">1225</i>&nbsp;            return null;</b>
<i class="no-highlight">1226</i>&nbsp;        }
<i class="no-highlight">1227</i>&nbsp;
<i class="no-highlight">1228</i>&nbsp;        public void forEachRemaining(Consumer&lt;? super E&gt; action) {
<i class="no-highlight">1229</i>&nbsp;            Node&lt;E&gt; p; int n;
<b class="nc"><i class="no-highlight">1230</i>&nbsp;            if (action == null) throw new NullPointerException();</b>
<b class="nc"><i class="no-highlight">1231</i>&nbsp;            if ((n = getEst()) &gt; 0 &amp;&amp; (p = current) != null) {</b>
<b class="nc"><i class="no-highlight">1232</i>&nbsp;                current = null;</b>
<b class="nc"><i class="no-highlight">1233</i>&nbsp;                est = 0;</b>
<i class="no-highlight">1234</i>&nbsp;                do {
<b class="nc"><i class="no-highlight">1235</i>&nbsp;                    E e = p.item;</b>
<b class="nc"><i class="no-highlight">1236</i>&nbsp;                    p = p.next;</b>
<b class="nc"><i class="no-highlight">1237</i>&nbsp;                    action.accept(e);</b>
<b class="nc"><i class="no-highlight">1238</i>&nbsp;                } while (p != null &amp;&amp; --n &gt; 0);</b>
<i class="no-highlight">1239</i>&nbsp;            }
<b class="nc"><i class="no-highlight">1240</i>&nbsp;            if (list.modCount != expectedModCount)</b>
<b class="nc"><i class="no-highlight">1241</i>&nbsp;                throw new ConcurrentModificationException();</b>
<i class="no-highlight">1242</i>&nbsp;        }
<i class="no-highlight">1243</i>&nbsp;
<i class="no-highlight">1244</i>&nbsp;        public boolean tryAdvance(Consumer&lt;? super E&gt; action) {
<i class="no-highlight">1245</i>&nbsp;            Node&lt;E&gt; p;
<b class="nc"><i class="no-highlight">1246</i>&nbsp;            if (action == null) throw new NullPointerException();</b>
<b class="nc"><i class="no-highlight">1247</i>&nbsp;            if (getEst() &gt; 0 &amp;&amp; (p = current) != null) {</b>
<b class="nc"><i class="no-highlight">1248</i>&nbsp;                --est;</b>
<b class="nc"><i class="no-highlight">1249</i>&nbsp;                E e = p.item;</b>
<b class="nc"><i class="no-highlight">1250</i>&nbsp;                current = p.next;</b>
<b class="nc"><i class="no-highlight">1251</i>&nbsp;                action.accept(e);</b>
<b class="nc"><i class="no-highlight">1252</i>&nbsp;                if (list.modCount != expectedModCount)</b>
<b class="nc"><i class="no-highlight">1253</i>&nbsp;                    throw new ConcurrentModificationException();</b>
<b class="nc"><i class="no-highlight">1254</i>&nbsp;                return true;</b>
<i class="no-highlight">1255</i>&nbsp;            }
<b class="nc"><i class="no-highlight">1256</i>&nbsp;            return false;</b>
<i class="no-highlight">1257</i>&nbsp;        }
<i class="no-highlight">1258</i>&nbsp;
<i class="no-highlight">1259</i>&nbsp;        public int characteristics() {
<b class="nc"><i class="no-highlight">1260</i>&nbsp;            return Spliterator.ORDERED | Spliterator.SIZED | Spliterator.SUBSIZED;</b>
<i class="no-highlight">1261</i>&nbsp;        }
<i class="no-highlight">1262</i>&nbsp;    }
<i class="no-highlight">1263</i>&nbsp;
<i class="no-highlight">1264</i>&nbsp;}
</div>
</pre>
</div>

<script type="text/javascript">
(function() {
    var msie = false, msie9 = false;
    /*@cc_on
      msie = true;
      @if (@_jscript_version >= 9)
        msie9 = true;
      @end
    @*/

    if (!msie || msie && msie9) {
        var codeBlock = document.getElementById('sourceCode');

        if (codeBlock) {
            hljs.highlightBlock(codeBlock);
        }
    }
})();
</script>

<div class="footer">
    
    <div style="float:right;">generated on 2022-04-24 17:27</div>
</div>
</body>
</html>
